Borrowing-TrackerBackend/equipment_tracker/accounts/views.py

26 lines
1.1 KiB
Python

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
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"})