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

Ac 7 examination #1673

Merged
merged 2 commits into from
Dec 7, 2024
Merged
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
25 changes: 14 additions & 11 deletions FusionIIIT/applications/examination/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from django.views.generic import View
import traceback
from django.http import HttpResponse
from django.conf import settings
from django.contrib.auth import get_user_model
import csv
import json
from openpyxl import Workbook
Expand Down Expand Up @@ -1088,27 +1090,27 @@ def submitGradesProf(request):
@login_required(login_url="/accounts/login")
def download_template(request):
des = request.session.get("currentDesignationSelected")
if des == "acadadmin" or str(des) == "Associate Professor" or str(des) == "Professor" or str(des) == "Assistant Professor" or des=="Dean Academic" :
pass
else:
if request.is_ajax(): # For AJAX or JSON requests
if des not in ["acadadmin", "Associate Professor", "Professor", "Assistant Professor", "Dean Academic"]:
if request.is_ajax():
return JsonResponse({"success": False, "error": "Access denied."}, status=403)
else: # For non-AJAX requests
else:
return HttpResponseRedirect('/dashboard/')

course = request.GET.get('course')
year = request.GET.get('year')

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

try:

# Fetching the custom user model
User = get_user_model()

course_info = course_registration.objects.filter(
course_id_id=course,
working_year=year
)


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

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

# Write header
writer.writerow(["roll_no", "grade", "remarks"])
writer.writerow(["roll_no", "name", "grade", "remarks"])

# Write student roll numbers
# Write student roll numbers and names
for entry in course_info:
student_entry = entry.student_id
writer.writerow([student_entry.id_id, "", ""])
# Fetching the user instance dynamically
student_user = User.objects.get(username=student_entry.id_id)
writer.writerow([student_entry.id_id, student_user.first_name+" "+student_user.last_name, "", ""])

return response

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

Expand Down
Loading