mirror of
https://github.com/lemeow125/Borrowing-TrackerBackend.git
synced 2025-04-27 10:11:24 +08:00
Add clearance viewset for student
This commit is contained in:
parent
5c8a99675d
commit
372e466744
5 changed files with 56 additions and 9 deletions
|
@ -52,3 +52,7 @@ class UserRegistrationSerializer(serializers.ModelSerializer):
|
|||
user.save()
|
||||
|
||||
return user
|
||||
|
||||
|
||||
class ClearanceSerializer(serializers.Serializer):
|
||||
cleared = serializers.CharField()
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
from accounts.views import ClearanceViewSet
|
||||
urlpatterns = [
|
||||
path('', include('djoser.urls')),
|
||||
path('', include('djoser.urls.jwt')),
|
||||
path('clearance/', ClearanceViewSet.as_view()),
|
||||
]
|
||||
|
|
|
@ -1,3 +1,26 @@
|
|||
from django.shortcuts import render
|
||||
from transactions.models import Transaction
|
||||
from accounts.permissions import IsStudent
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import generics
|
||||
from accounts.serializers import ClearanceSerializer
|
||||
from rest_framework.response import Response
|
||||
|
||||
# Create your views here.
|
||||
|
||||
class ClearanceViewSet(generics.GenericAPIView):
|
||||
# Check all transactions associated with the student. If any are uncleared or not finalized, return uncleared
|
||||
http_method_names = ['get']
|
||||
permission_classes = [IsAuthenticated, IsStudent]
|
||||
serializer_class = ClearanceSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
user = self.request.user
|
||||
return Transaction.objects.filter(borrower=user)
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
queryset = self.get_queryset()
|
||||
status_list = ["Approved", "Borrowed", "Returned: Pending Checking",
|
||||
"With Breakages: Pending Resolution"]
|
||||
for transaction in queryset:
|
||||
if transaction.transaction_status in status_list:
|
||||
return Response({"cleared": "Uncleared"})
|
||||
return Response({"cleared": "Cleared"})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue