Skip to content
Merged
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
7 changes: 5 additions & 2 deletions FusionIIIT/applications/academic_procedures/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3279,14 +3279,16 @@ def student_list_requests(request):
else:
academic_year, semester_type = generate_current_session(datetime.datetime.now().year, student.curr_semester_no)

qs = CourseReplacementRequest.objects.filter(student=student, academic_year=academic_year, semester_type = semester_type).order_by('-created_at')
qs = CourseReplacementRequest.objects.filter(student=student, academic_year=academic_year, semester_type = semester_type).select_related('old_course', 'new_course', 'course_slot').order_by('-created_at')
out = []
for r in qs:
out.append({
'id': r.id,
'slot': r.course_slot.name,
'old_course': r.old_course.code,
'old_course_name': r.old_course.name,
'new_course': r.new_course.code,
'new_course_name': r.new_course.name,
'status': r.status,
'academic_year': r.academic_year,
'semester_type': r.semester_type,
Expand Down Expand Up @@ -3404,13 +3406,14 @@ def student_registrations_for_drop(request):
eligibility_resp = get_drop_registration_eligibility(timezone.now().date(), student.curr_semester_no, datetime.datetime.now().year)
if isinstance(eligibility_resp, JsonResponse):
return eligibility_resp
regs = course_registration.objects.filter(student_id=student, semester_id__semester_no = student.curr_semester_no ).order_by('course_slot_id__name')
regs = course_registration.objects.filter(student_id=student, semester_id__semester_no = student.curr_semester_no ).select_related('course_id', 'course_slot_id').order_by('course_slot_id__name')
out = []
for reg in regs:
out.append({
'id': reg.id,
'slot': reg.course_slot_id.name,
'course': reg.course_id.code,
'course_name': reg.course_id.name,
'academic_year': reg.session,
'semester_type': reg.semester_type,
})
Expand Down
53 changes: 43 additions & 10 deletions FusionIIIT/applications/academic_procedures/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,22 +894,55 @@ def approve_branch_change(request):
choices.append(values[i])
else:
continue

from applications.programme_curriculum.models import Discipline, Batch

changed_branch = []
changed_students = []

for i in range(len(branches)):
get_student = ExtraInfo.objects.all().select_related('user','department').filter(id=choices[i][:7])
get_student = get_student[0]
branch = DepartmentInfo.objects.all().filter(name=branches[i])
get_student.department = branch[0]
get_student = ExtraInfo.objects.select_related('user','department').filter(id=choices[i][:7]).first()
if not get_student:
continue

branch = DepartmentInfo.objects.filter(name=branches[i]).first()
if not branch:
continue

get_student.department = branch
changed_branch.append(get_student)
student = Student.objects.all().select_related('id','id__user','id__department').filter(id=choices[i][:7]).first()
change = BranchChange.objects.select_related('branches','user','user__id','user__id__user','user__id__department').all().filter(user=student)
change = change[0]
change.delete()

# Update Student batch_id to match new discipline
student = Student.objects.select_related('id','id__user','id__department','batch_id').filter(id=choices[i][:7]).first()
if student and student.batch_id:
try:
new_discipline = Discipline.objects.filter(name=branches[i]).first()
if new_discipline:
new_batch = Batch.objects.filter(
year=student.batch_id.year,
name=student.batch_id.name,
discipline=new_discipline
).first()
if new_batch:
student.batch_id = new_batch
changed_students.append(student)
except Exception as e:
pass

if student:
change = BranchChange.objects.filter(user=student).first()
if change:
change.delete()

try:
ExtraInfo.objects.bulk_update(changed_branch,['department'])
if changed_branch:
ExtraInfo.objects.bulk_update(changed_branch, ['department'])
if changed_students:
Student.objects.bulk_update(changed_students, ['batch_id'])
messages.info(request, 'Apply for branch change successfull')
except:
except Exception as e:
messages.info(request, 'Unable to proceed, we will get back to you very soon')

return HttpResponseRedirect('/academic-procedures/main')

else:
Expand Down
25 changes: 20 additions & 5 deletions FusionIIIT/applications/examination/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,23 +430,37 @@ def download_template(request):
# Get course information from the first matched registration.
course_obj = course_info.first().course_id
response = HttpResponse(content_type="text/csv")
filename = f"{course_obj.code}_template_{session_year}.csv"
course_name_clean = course_obj.name.replace(' ', '_').replace('/', '-')[:50]
semester_type_clean = semester_type.replace(' ', '_')
filename = f"{course_name_clean}_{semester_type_clean}_{session_year}.csv"
response['Content-Disposition'] = f'attachment; filename="{filename}"'

writer = csv.writer(response)
writer.writerow(["roll_no", "name", "grade", "remarks", "semester"])
writer.writerow(["roll_no", "name", "branch", "grade", "remarks", "semester"])

# Write a CSV row for each student registration.
for entry in course_info:
student_entry = entry.student_id
# Assuming student_entry.id_id is the student's roll number.
student_user = User.objects.get(username=student_entry.id_id)
branch_acronym = ""
if student_entry.batch_id:
try:
branch_acronym = student_entry.batch_id.discipline.acronym
except AttributeError:
pass
if not branch_acronym and student_entry.id.department:
branch_acronym = student_entry.id.department.name
semester_no = ""
if entry.course_slot_id and entry.course_slot_id.semester:
semester_no = entry.course_slot_id.semester.semester_no

writer.writerow([
student_entry.id_id,
f"{student_user.first_name} {student_user.last_name}",
branch_acronym,
"",
"",
""
semester_no
])

return response
Expand Down Expand Up @@ -3010,10 +3024,11 @@ def post(self, request):
# Check if the current roll number is registered.
is_registered = roll_no in registered_rollnos

# Add additional data (e.g. name, grades, remarks, semester) as in CSV
# Add additional data (e.g. name, grades, remarks, semester, branch) as in CSV
preview_rows.append({
"roll_no": roll_no,
"name": row["name"],
"branch": row.get("branch", ""),
"grades": row["grade"],
"remarks": row["remarks"],
"semester": row["semester"],
Expand Down