-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathviews.py
More file actions
57 lines (47 loc) · 2.27 KB
/
views.py
File metadata and controls
57 lines (47 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from django.shortcuts import render
from students.models import Attendance
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated
from .serializers import ResultInfoSerializer, StudentInfoSerializer
from .models import Result
from students.models import StudentInfo
# Create your views here.
@api_view()
def student_attendance(request, student_class, student_id):
try:
Attendance.objects.create_attendance(student_class, student_id)
return Response({"Status": "Atendance Counted Successfully"}, status=status.HTTP_200_OK)
except Exception as err:
print(err)
return Response({"Status": "Attendance already has taken"}, status=status.HTTP_400_BAD_REQUEST)
# Class Based View (CBV)
class StudentAttendance(APIView):
def get(self, request, student_class, student_id):
try:
Attendance.objects.create_attendance(student_class, student_id)
return Response({"Status": "Atendance Counted Successfully"}, status=status.HTTP_200_OK)
except Exception as err:
print(err)
return Response({"Status": "Attendance already has taken"}, status=status.HTTP_400_BAD_REQUEST)
class ResultInfo(APIView):
permission_classes = (IsAuthenticated,)
def post(self, request):
result_serializer = ResultInfoSerializer(data=request.data)
if result_serializer.is_valid():
board = result_serializer.validated_data["board"]
roll = result_serializer.validated_data["roll"]
result_obj = Result.objects.get(board=board, roll=roll)
return Response({"Result": result_obj.gpa})
return Response(result_serializer.errors)
class CreateStudentInfo(APIView):
permission_classes = (IsAuthenticated,)
def post(self, request):
create_student_serializer = StudentInfoSerializer(data=request.data)
if create_student_serializer.is_valid():
create_student_serializer.save()
return Response({"Status": "Success"}, status=status.HTTP_200_OK)
else:
return Response({"Status": create_student_serializer.errors}, status=status.HTTP_400_BAD_REQUEST)