Skip to content

Commit 921e33b

Browse files
authored
Merge pull request #1673 from Lone24wolf/ac-7-examination
2 parents 8d73f26 + aa48897 commit 921e33b

File tree

1 file changed

+14
-11
lines changed
  • FusionIIIT/applications/examination

1 file changed

+14
-11
lines changed

FusionIIIT/applications/examination/views.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from django.views.generic import View
44
import traceback
55
from django.http import HttpResponse
6+
from django.conf import settings
7+
from django.contrib.auth import get_user_model
68
import csv
79
import json
810
from openpyxl import Workbook
@@ -1088,27 +1090,27 @@ def submitGradesProf(request):
10881090
@login_required(login_url="/accounts/login")
10891091
def download_template(request):
10901092
des = request.session.get("currentDesignationSelected")
1091-
if des == "acadadmin" or str(des) == "Associate Professor" or str(des) == "Professor" or str(des) == "Assistant Professor" or des=="Dean Academic" :
1092-
pass
1093-
else:
1094-
if request.is_ajax(): # For AJAX or JSON requests
1093+
if des not in ["acadadmin", "Associate Professor", "Professor", "Assistant Professor", "Dean Academic"]:
1094+
if request.is_ajax():
10951095
return JsonResponse({"success": False, "error": "Access denied."}, status=403)
1096-
else: # For non-AJAX requests
1096+
else:
10971097
return HttpResponseRedirect('/dashboard/')
1098+
10981099
course = request.GET.get('course')
10991100
year = request.GET.get('year')
11001101

11011102
if not course or not year:
11021103
return JsonResponse({'error': 'Course and year are required'}, status=400)
11031104

11041105
try:
1105-
1106+
# Fetching the custom user model
1107+
User = get_user_model()
1108+
11061109
course_info = course_registration.objects.filter(
11071110
course_id_id=course,
11081111
working_year=year
11091112
)
11101113

1111-
11121114
if not course_info.exists():
11131115
return JsonResponse({'error': 'No registration data found for the provided course and year'}, status=404)
11141116

@@ -1121,17 +1123,18 @@ def download_template(request):
11211123
writer = csv.writer(response)
11221124

11231125
# Write header
1124-
writer.writerow(["roll_no", "grade", "remarks"])
1126+
writer.writerow(["roll_no", "name", "grade", "remarks"])
11251127

1126-
# Write student roll numbers
1128+
# Write student roll numbers and names
11271129
for entry in course_info:
11281130
student_entry = entry.student_id
1129-
writer.writerow([student_entry.id_id, "", ""])
1131+
# Fetching the user instance dynamically
1132+
student_user = User.objects.get(username=student_entry.id_id)
1133+
writer.writerow([student_entry.id_id, student_user.first_name+" "+student_user.last_name, "", ""])
11301134

11311135
return response
11321136

11331137
except Exception as e:
1134-
# Log the error (consider using Python's logging module)
11351138
print(f"Error in download_template: {str(e)}")
11361139
return JsonResponse({'error': 'An unexpected error occurred'}, status=500)
11371140

0 commit comments

Comments
 (0)