diff --git a/FusionIIIT/applications/academic_information/utils.py b/FusionIIIT/applications/academic_information/utils.py index 49e2e75f5..28d06a1af 100644 --- a/FusionIIIT/applications/academic_information/utils.py +++ b/FusionIIIT/applications/academic_information/utils.py @@ -97,57 +97,72 @@ def random_algo(batch,sem,year,course_slot) : return 1 @transaction.atomic -def allocate(request) : +def allocate(request): batch = request.POST.get('batch') sem = request.POST.get('sem') year = request.POST.get('year') - unique_course_slot = InitialRegistration.objects.filter(Q(semester_id__semester_no = sem) & Q(student_id__batch = batch)).values('course_slot_id', 'registration_type').distinct() + unique_course_slot = InitialRegistration.objects.filter(Q(semester_id_semester_no=sem) & Q( + student_id_batch=batch)).values('course_slot_id').distinct() unique_course_name = [] - try: - with transaction.atomic() : - for entry in unique_course_slot : - course_slot_object = CourseSlot.objects.get(id=entry['course_slot_id']) - print(course_slot_object) - if course_slot_object.type != "Open Elective": - # Fetch students registered in this course slot - students = InitialRegistration.objects.filter( - Q(semester_id__semester_no=sem) & - Q(course_slot_id=course_slot_object) & - Q(student_id__batch=batch) - ).values_list('student_id', flat=True) - - # Allocate each student directly to FinalRegistration - for student_id in students: - student = Student.objects.get(id=student_id) - semester = Semester.objects.get(semester_no=sem, curriculum=student.batch_id.curriculum) - print(semester.id) - # course = Course.objects.get(id=course_slot_object.courses.id) - course_id = course_slot_object.courses.values_list('id', flat=True).first() - # Retrieve the Course instance - course = Course.objects.get(id=course_id) - - # Insert directly into FinalRegistration - FinalRegistration.objects.create( - student_id=student, - verified=False, - semester_id=semester, - course_id=course, - course_slot_id=course_slot_object, - registration_type=entry['registration_type'] - ) + try: + with transaction.atomic(): + for entry in unique_course_slot: + course_slot_object = CourseSlot.objects.get( + id=entry['course_slot_id']) + if course_slot_object.type != "Open Elective": + # Fetch students registered in this course slot + students = InitialRegistration.objects.filter( + Q(semester_id__semester_no=sem) & + Q(course_slot_id=course_slot_object) & + Q(student_id__batch=batch) + ).values_list('student_id', flat=True) + + # Allocate each student directly to FinalRegistration + for student_id in students: + student = Student.objects.get(id=student_id) + semester = Semester.objects.get( + semester_no=sem, curriculum=student.batch_id.curriculum) + regis = InitialRegistration.objects.filter( + course_slot_id_id=course_slot_object, + student_id_id=student_id + ).values_list('registration_type', flat=True).first() + # course = Course.objects.get(id=course_slot_object.courses.id) + # course_id = course_slot_object.courses.values_list('id', flat=True).first() + course_id = InitialRegistration.objects.filter( + course_slot_id_id=course_slot_object, + student_id_id=student_id + ).values_list('course_id', flat=True).first() + + # Retrieve the Course instance + course = Course.objects.get(id=course_id) + + # Insert directly into FinalRegistration + # if course_slot_object.name in unique_course_name: + # print("skip") + # continue + + FinalRegistration.objects.create( + student_id=student, + verified=False, + semester_id=semester, + course_id=course, + course_slot_id=course_slot_object, + registration_type=regis + ) + + unique_course_name.append(course_slot_object.name) + elif course_slot_object.type == "Open Elective": # Runs only for open elective course slots + if course_slot_object.name not in unique_course_name: + stat = random_algo(batch, sem, year, course_slot_object.name) unique_course_name.append(course_slot_object.name) - elif course_slot_object.type == "Open Elective": # Runs only for open elective course slots - if course_slot_object.name not in unique_course_name: - stat = random_algo(batch,sem,year,course_slot_object.name) - unique_course_name.append(course_slot_object.name) - if(stat == -1) : - print(course_slot_object.name) - raise Exception("seats not enough for course_slot"+str(course_slot_object.name)) - - return JsonResponse({'status': 1 , 'message' : "course allocation successful"}) + if (stat == -1): + print("Seats not enough for course_slot", str(course_slot_object.name), "terminating process...") + raise Exception("seats not enough for course_slot "+str(course_slot_object.name)) + + return JsonResponse({'status': 1, 'message': "course allocation successful"}) except: - return JsonResponse({'status': -1 , 'message' : "seats not enough for some course_slot"}) + return JsonResponse({'status': -1, 'message': "seats not enough for some course_slot"}) def view_alloted_course(request) : batch = request.POST.get('batch') diff --git a/FusionIIIT/applications/academic_procedures/views.py b/FusionIIIT/applications/academic_procedures/views.py index accc95f53..8557e15b0 100644 --- a/FusionIIIT/applications/academic_procedures/views.py +++ b/FusionIIIT/applications/academic_procedures/views.py @@ -1655,7 +1655,7 @@ def allot_courses(request): print(course_code.strip() , course_name.strip()) course = Courses.objects.get(code=course_code.strip(),name=course_name.strip()) if(roll_no not in currroll): - student_check=StudentRegistrationChecks(student_id = student, semester_id = sem_id, pre_registration_flag = True,final_registration_flag = False) + student_check=StudentRegistrationChecks(student_id = student, semester_id = sem_id, pre_registration_flag = True,final_registration_flag = True) student_checks.append(student_check) currroll.add(roll_no) # print(">>>>>",roll_no,course_slot_name,course_code,course_name) @@ -1665,7 +1665,7 @@ def allot_courses(request): course_id=course,semester_id=sem_id,priority=1) pre_registrations.append(pre_registration) final_registration=FinalRegistration(student_id=student,course_slot_id=course_slot, - course_id=course,semester_id=sem_id) + course_id=course,semester_id=sem_id, verified=True ) final_registrations.append(final_registration) courseregistration=course_registration(working_year=datetime.datetime.now().year,course_id=course,semester_id=sem_id,student_id=student,course_slot_id=course_slot) @@ -2619,8 +2619,9 @@ def course_list(request): student_id = request_body['student_id'] semester_id = request_body['semester_id'] - final_registration_table = FinalRegistration.objects.all().filter(semester_id = semester_id, verified = False) - final = final_registration_table.filter(student_id = student_id, semester_id = semester_id) + # final_registration_table = FinalRegistration.objects.all().filter(semester_id = semester_id, verified = False) + # final = final_registration_table.filter(student_id = student_id, semester_id = semester_id) + final = FinalRegistration.objects.all().filter(semester_id__semester_no = semester_id, student_id__id=student_id, verified = False) html = render_to_string('academic_procedures/student_course_list.html',{"course_list":final}, request) return HttpResponse(json.dumps({'html': html}),content_type="application/json") @@ -2717,6 +2718,14 @@ def auto_verify_registration(request): with transaction.atomic(): for obj in final_register_list: o = FinalRegistration.objects.filter(id= obj.id).update(verified = True) + course_registration.objects.create( + student_id=obj.student_id, + course_id=obj.course_id, + semester_id=obj.semester_id, + course_slot_id=obj.course_slot_id, + registration_type=obj.registration_type, + working_year=demo_date.year # Set the current year + ) academics_module_notif(request.user, student.id.user, 'registration_approved') Student.objects.filter(id = student_id).update(curr_semester_no = sem_no)