Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetching and updating the grades #1298

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions FusionIIIT/applications/examination/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
# url(r'^add_student/', views.add_student, name='add_student'),

url(r'^update_hidden_grade/', views.update_hidden_grade, name='update_hidden_grade'),

url(r'^update_hidden_grade_multiple/', views.update_hidden_grade_multiple, name='update_hidden_grade_multiple'),

url(r'^enter_student_grades/', views.enter_student_grades, name='enter_student_grades'),



url(r'^update_authenticator/', views.update_authenticator, name='update_authenticator'),
Expand Down
209 changes: 93 additions & 116 deletions FusionIIIT/applications/examination/api/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
from django.db.models.query_utils import Q
from django.http import request,HttpResponse
from django.shortcuts import get_object_or_404, render, HttpResponse,redirect
from django.http import request, HttpResponse
from django.shortcuts import get_object_or_404, render, HttpResponse, redirect
from django.http import HttpResponse, HttpResponseRedirect
import itertools
from django.contrib import messages
Expand All @@ -12,59 +13,16 @@
from applications.globals.models import (DepartmentInfo, Designation,
ExtraInfo, Faculty, HoldsDesignation)

from applications.academic_procedures.models import(course_registration)
from applications.examination.models import(hidden_grades , authentication , grade)
from applications.academic_procedures.models import (course_registration)
from applications.examination.models import (
hidden_grades, authentication, grade)
from . import serializers

from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response


#Login
# @login_required(login_url='/accounts/login')
# def exam(request):
# """
# This function is used to Differenciate acadadmin and all other user.

# @param:
# request - contains metadata about the requested page

# @variables:
# user_details - Gets the information about the logged in user.
# des - Gets the designation about the looged in user.
# """
# user_details = ExtraInfo.objects.get(user = request.user)
# des = HoldsDesignation.objects.all().filter(user = request.user).first()
# if str(des.designation) == "Associate Professor" or str(des.designation) == "Professor" or str(des.designation) == "Assistant Professor" :
# return HttpResponseRedirect('/examination/submit/')
# elif str(request.user) == "acadadmin" :
# return HttpResponseRedirect('/examination/submit/')

# return HttpResponseRedirect('/dashboard/')

# @login_required(login_url='/accounts/login')




#Get all students
# @api_view(['GET'])
# def fetch_student_details(request):
# if request.method == 'GET':
# # obj=course_registration.objects.filter(course_id__id=course_id, student_id__batch=batch)
# obj=course_registration.objects.all()
# obj_serialized = serializers.CourseRegistrationSerializer(obj , many=True).data
# resp = {
# 'objt' : obj_serialized
# }

# return Response(data=resp , status=status.HTTP_200_OK)





@api_view(['GET', 'POST'])
def fetch_student_details(request):
if request.method == 'GET':
Expand All @@ -78,7 +36,8 @@ def fetch_student_details(request):
obj = course_registration.objects.filter(course_id=course_id)

# Serialize the queryset
obj_serialized = serializers.CourseRegistrationSerializer(obj, many=True).data
obj_serialized = serializers.CourseRegistrationSerializer(
obj, many=True).data

# Prepare the response data
resp = {
Expand All @@ -87,7 +46,7 @@ def fetch_student_details(request):

# Return the response
return Response(data=resp, status=status.HTTP_200_OK)

elif request.method == 'POST':
# Extract data from the request
data = request.data
Expand All @@ -101,7 +60,8 @@ def fetch_student_details(request):

# Check if the entry already exists
try:
hidden_grade_obj = hidden_grades.objects.get(student_id=student_id, course_id=course_id)
hidden_grade_obj = hidden_grades.objects.get(
student_id=student_id, course_id=course_id)
# If exists, update the grade
hidden_grade_obj.grade = grade
hidden_grade_obj.save()
Expand All @@ -115,7 +75,50 @@ def fetch_student_details(request):
)

return Response({'message': 'Hidden grade added successfully'}, status=status.HTTP_201_CREATED)

@api_view(['POST'])
def enter_student_grades(request):
if request.method == 'POST':
# Extract data from the request
data = request.data.get('grades', [])

if not data:
return Response({'error': 'No data provided'}, status=status.HTTP_400_BAD_REQUEST)

for grade_data in data:
student_id = grade_data.get('student_id')
course_id = grade_data.get('course_id')
semester_id = grade_data.get('semester_id')
grade = grade_data.get('grade')

if student_id is None or course_id is None or semester_id is None or grade is None:
return Response({'error': 'Incomplete data provided'}, status=status.HTTP_400_BAD_REQUEST)

try:
hidden_grade_obj = hidden_grades.objects.get(
student_id=student_id,
course_id=course_id,
semester_id=semester_id
)
# If exists, update the grade
hidden_grade_obj.grade = grade
hidden_grade_obj.save()
except hidden_grades.DoesNotExist:
# If doesn't exist, create a new entry
hidden_grade_obj = hidden_grades.objects.create(
student_id=student_id,
course_id=course_id,
semester_id=semester_id,
grade=grade
)

return Response({'message': 'Hidden grades added successfully'}, status=status.HTTP_201_CREATED)
else:
return Response({'error': 'Unsupported method'}, status=status.HTTP_405_METHOD_NOT_ALLOWED)






@api_view(['PATCH'])
Expand All @@ -129,7 +132,8 @@ def update_hidden_grade(request):
grade = request.data['grade']
# Get the hidden grade object for the given course_id and student_id
try:
hidden_grade = hidden_grades.objects.get(course_id=course_id, student_id=student_id)
hidden_grade = hidden_grades.objects.get(
course_id=course_id, student_id=student_id)
hidden_grade.grade = grade
hidden_grade.save()
return JsonResponse({'message': 'Grade updated successfully'}, status=200)
Expand All @@ -139,21 +143,49 @@ def update_hidden_grade(request):
return JsonResponse({'error': 'Incomplete data provided'}, status=400)
else:
return JsonResponse({'error': 'Unsupported method'}, status=405)





@api_view(['PATCH'])
def update_hidden_grade_multiple(request):
if request.method == 'PATCH':
# Check if the data is provided in the request
if 'grades' in request.data:
grades_data = request.data['grades']
for grade_data in grades_data:
course_id = grade_data.get('course_id')
student_id = grade_data.get('student_id')
semester_id = grade_data.get('semester_id')
grade = grade_data.get('grade')

if course_id is None or student_id is None or semester_id is None or grade is None:
return Response({'error': 'Incomplete data provided for one of the grades'}, status=400)

# Get the hidden grade object for the given course_id, student_id, and semester_id
try:
hidden_grade = hidden_grades.objects.get(
course_id=course_id, student_id=student_id, semester_id=semester_id)
hidden_grade.grade = grade
hidden_grade.save()
except hidden_grades.DoesNotExist:
# If the grade doesn't exist, create a new one
hidden_grade = hidden_grades.objects.create(
course_id=course_id, student_id=student_id, semester_id=semester_id, grade=grade)
hidden_grade.save()

return Response({'message': 'Grades updated successfully'}, status=200)
else:
return Response({'error': 'No grade data provided'}, status=400)
else:
return Response({'error': 'Unsupported method'}, status=405)


from datetime import datetime
@api_view(['PATCH'])
def update_authenticator(request):
if request.method == 'PATCH':
# Extract year and authenticator number from the request
year = request.data.get('year')
authenticator_number = request.data.get('authenticator_number')

# Validate year format
try:
datetime.strptime(year, '%Y')
Expand All @@ -162,7 +194,7 @@ def update_authenticator(request):

# Retrieve all authentication objects for the given year
auth_objects = authentication.objects.filter(year__year=year)

if not auth_objects.exists():
return Response({'error': 'No authentication entries found for the provided year.'}, status=status.HTTP_404_NOT_FOUND)

Expand All @@ -176,14 +208,12 @@ def update_authenticator(request):
auth_object.authenticator_3 = not auth_object.authenticator_3
else:
return Response({'error': 'Invalid authenticator number'}, status=status.HTTP_400_BAD_REQUEST)

auth_object.save()

return Response({'message': f'Authenticator {authenticator_number} toggled successfully for the year {year}'}, status=status.HTTP_200_OK)




@api_view(['GET'])
def publish_grade(request):
course_id = request.GET.get('course_id')
Expand All @@ -192,7 +222,8 @@ def publish_grade(request):
if auth_obj:
if auth_obj.authenticator_1 and auth_obj.authenticator_2 and auth_obj.authenticator_3:
# Get hidden grades for the given course
hidden_grades_list = hidden_grades.objects.filter(course_id=course_id)
hidden_grades_list = hidden_grades.objects.filter(
course_id=course_id)

# Update final grades table
for hidden_grade in hidden_grades_list:
Expand All @@ -217,57 +248,3 @@ def publish_grade(request):
return JsonResponse({'error': 'Not all authenticators are True'}, status=400)
else:
return JsonResponse({'error': 'Authentication object not present'}, status=404)




# def submit(request):

# return render(request,'../templates/examination/submit.html' , {})

# @login_required(login_url='/accounts/login')
# def verify(request):
# return render(request,'../templates/examination/verify.html' , {})

# @login_required(login_url='/accounts/login')
# def publish(request):
# return render(request,'../templates/examination/publish.html' ,{})


# @login_required(login_url='/accounts/login')
# def notReady_publish(request):
# return render(request,'../templates/examination/notReady_publish.html',{})


# @api_view(['POST'])
# def publish_result(request):









# def add_student(request):
# if request.method == 'POST':
# # Assuming the POST request contains necessary data for a new student
# student_id = request.POST.get('student_id')
# course_id = request.POST.get('course_id')
# semester_id = request.POST.get('semester_id')
# grades = request.POST.get('grades')

# # Create a new private_grade object
# new_student = hidden_grades.objects.create(
# student_id=student_id,
# course_id=course_id,
# semester_id=semester_id,
# grades=grades
# )

# return JsonResponse({'message': 'Student added successfully'})
# else:
# return JsonResponse({'error': 'Invalid request method'}, status=400)


4 changes: 4 additions & 0 deletions FusionIIIT/applications/examination/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django import forms

class StudentGradeForm(forms.Form):
grades = forms.CharField(widget=forms.MultipleHiddenInput)
9 changes: 0 additions & 9 deletions FusionIIIT/applications/examination/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,3 @@ class grade(models.Model):
curriculum = models.CharField(max_length=50)
semester_id = models.CharField(max_length=10)
grade = models.CharField(max_length=5,default="B")

# class final_grades(models.Model):
# student_id = models.CharField(max_length=20)
# course_id = models.CharField(max_length=50)
# semester_id = models.CharField(max_length=10)
# grade = models.CharField(max_length=5,default="")

# # def __str__(self):
# # return f"{self.student_id}, {self.course_id}"
39 changes: 37 additions & 2 deletions FusionIIIT/applications/examination/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,44 @@
from django.urls import path, include
from . import views
from django.contrib import admin
from .views import update_authentication
from .views import DownloadExcelView


app_name = 'examination'

urlpatterns = [
url(r'^api/', include('applications.examination.api.urls'))
url(r'^api/', include('applications.examination.api.urls')),
url(r'^$', views.exam, name='exam'),
url(r'submit/', views.submit, name='submit'),
url(r'verify/', views.verify, name='verify'),
url(r'publish/', views.publish, name='publish'),
url(r'notReady_publish/', views.notReady_publish, name='notReady_publish'),
url(r'announcement/', views.announcement, name='announcement'),
url(r'timetable/', views.timetable, name='timetable'),

#entering and updataing grade
path('entergrades/', views.entergrades, name='entergrades'),
path('update_hidden_grades_multiple/', views.Updatehidden_gradesMultipleView.as_view(),
name='update_hidden_grades_multiple'),
path('verifygrades/', views.verifygrades, name='verifygrades'),
path('update_hidden_grades_multiple/', views.Updatehidden_gradesMultipleView.as_view(),
name='update_hidden_grades_multiple'),
path('submit_hidden_grades_multiple/', views.Submithidden_gradesMultipleView.as_view(),
name='submit_hidden_grades_multiple'),

# authenticate
path('authenticate/', views.authenticate, name='authenticate'),
path('authenticategrades/', views.authenticategrades,
name='authenticategrades'),
path('update_authentication/', update_authentication.as_view(),
name='update_authentication'),

#download result
path('download_excel/', DownloadExcelView.as_view(), name='download_excel'),

# generate transcript
path('generate_transcript/', views.generate_transcript, name='generate_transcript'),
path('generate_transcript_form/', views.generate_transcript_form, name='generate_transcript_form'),
# url(r'entergrades/', views.entergrades, name='entergrades'),

]
Loading