1515import random
1616from django .db import transaction
1717time = timezone .now ()
18- def check_for_registration_complete (batch , sem , year ):
18+ def check_for_registration_complete (batch , sem , year , programme_type ):
1919 date = datetime .date .today ()
2020 try :
2121 pre_registration_date = Calendar .objects .filter (description = f"Pre Registration { sem } { year } " ).first ()
@@ -31,7 +31,7 @@ def check_for_registration_complete(batch, sem, year):
3131 if prd_start_date <= date <= prd_end_date :
3232 return {"status" : - 1 , "message" : "Registration is under process" }
3333
34- if FinalRegistration .objects .filter (Q (semester_id__semester_no = sem ) & Q (student_id__batch = batch )).exists () :
34+ if FinalRegistration .objects .filter (Q (semester_id__semester_no = sem ) & Q (student_id__batch = batch ) & Q ( student_id__batch_id__curriculum__programme__category = programme_type ) ).exists () :
3535 return {"status" : 2 , "message" : "Courses already allocated" }
3636
3737 return {"status" : 1 , "message" : "Courses not yet allocated" }
@@ -40,8 +40,8 @@ def check_for_registration_complete(batch, sem, year):
4040 return {"status" : - 3 , "message" : f"Internal Server Error: { str (e )} " }
4141
4242@transaction .atomic
43- def random_algo (batch ,sem ,year ,course_slot ) :
44- unique_course = InitialRegistration .objects .filter (Q (semester_id__semester_no = sem ) & Q ( course_slot_id__name = course_slot ) & Q (student_id__batch = batch )).values_list ('course_id' ,flat = True ).distinct ()
43+ def random_algo (batch ,sem ,year ,course_slot , programme_type ) :
44+ unique_course = InitialRegistration .objects .filter (Q (semester_id__semester_no = sem ) & Q ( course_slot_id__name = course_slot ) & Q (student_id__batch = batch ) & Q ( student_id__batch_id__curriculum__programme__category = programme_type ) ).values_list ('course_id' ,flat = True ).distinct ()
4545 max_seats = {}
4646 seats_alloted = {}
4747 present_priority = {}
@@ -54,7 +54,7 @@ def random_algo(batch,sem,year,course_slot) :
5454 present_priority [course ] = []
5555 next_priority [course ] = []
5656
57- priority_1 = InitialRegistration .objects .filter (Q (semester_id__semester_no = sem ) & Q ( course_slot_id__name = course_slot ) & Q (student_id__batch = batch ) & Q (priority = 1 ))
57+ priority_1 = InitialRegistration .objects .filter (Q (semester_id__semester_no = sem ) & Q ( course_slot_id__name = course_slot ) & Q (student_id__batch = batch ) & Q (priority = 1 ) & Q ( student_id__batch_id__curriculum__programme__category = programme_type ) )
5858 rem = len (priority_1 )
5959 if rem > total_seats :
6060 return - 1
@@ -86,7 +86,7 @@ def random_algo(batch,sem,year,course_slot) :
8686 seats_alloted [course ] += 1
8787 rem -= 1
8888 else :
89- next = InitialRegistration .objects .get (Q (student_id__id__id = random_student_selected [0 ]) & Q ( course_slot_id__name = course_slot ) & Q (semester_id__semester_no = sem ) & Q (student_id__batch = batch ) & Q (priority = p_priority + 1 ))
89+ next = InitialRegistration .objects .get (Q (student_id__id__id = random_student_selected [0 ]) & Q ( course_slot_id__name = course_slot ) & Q (semester_id__semester_no = sem ) & Q (student_id__batch = batch ) & Q (priority = p_priority + 1 ) & Q ( student_id__batch_id__curriculum__programme__category = programme_type ) )
9090 next_priority [next .course_id .id ].append ([next .student_id .id .id ,next .course_slot_id .id ])
9191 p_priority += 1
9292 present_priority = next_priority
@@ -99,9 +99,10 @@ def allocate(request):
9999 batch = request .POST .get ('batch' )
100100 sem = request .POST .get ('sem' )
101101 year = request .POST .get ('year' )
102+ programme_type = request .POST .get ('programme_type' )
102103
103104 unique_course_slot = InitialRegistration .objects .filter (
104- Q (semester_id__semester_no = sem ) & Q (student_id__batch = batch )
105+ Q (semester_id__semester_no = sem ) & Q (student_id__batch = batch ) & Q ( student_id__batch_id__curriculum__programme__category = programme_type )
105106 ).values ('course_slot_id' ).distinct ()
106107
107108 unique_course_name = []
@@ -115,7 +116,7 @@ def allocate(request):
115116 students = InitialRegistration .objects .filter (
116117 Q (semester_id__semester_no = sem ) &
117118 Q (course_slot_id = course_slot_object ) &
118- Q (student_id__batch = batch )
119+ Q (student_id__batch = batch ) & Q ( student_id__batch_id__curriculum__programme__category = programme_type )
119120 ).values_list ('student_id' , flat = True )
120121
121122 for student_id in students :
@@ -158,7 +159,7 @@ def allocate(request):
158159
159160 elif course_slot_object .type == "Open Elective" :
160161 if course_slot_object .name not in unique_course_name :
161- stat = random_algo (batch , sem , year , course_slot_object .name )
162+ stat = random_algo (batch , sem , year , course_slot_object .name , programme_type )
162163 unique_course_name .append (course_slot_object .name )
163164 if stat == - 1 :
164165 raise Exception (f"Seats not enough for course_slot { course_slot_object .name } " )
0 commit comments