@@ -97,57 +97,72 @@ def random_algo(batch,sem,year,course_slot) :
97
97
return 1
98
98
99
99
@transaction .atomic
100
- def allocate (request ) :
100
+ def allocate (request ):
101
101
batch = request .POST .get ('batch' )
102
102
sem = request .POST .get ('sem' )
103
103
year = request .POST .get ('year' )
104
- unique_course_slot = InitialRegistration .objects .filter (Q (semester_id__semester_no = sem ) & Q (student_id__batch = batch )).values ('course_slot_id' , 'registration_type' ).distinct ()
104
+ unique_course_slot = InitialRegistration .objects .filter (Q (semester_id_semester_no = sem ) & Q (
105
+ student_id_batch = batch )).values ('course_slot_id' ).distinct ()
105
106
unique_course_name = []
106
- try :
107
- with transaction .atomic () :
108
- for entry in unique_course_slot :
109
- course_slot_object = CourseSlot .objects .get (id = entry ['course_slot_id' ])
110
- print (course_slot_object )
111
- if course_slot_object .type != "Open Elective" :
112
- # Fetch students registered in this course slot
113
- students = InitialRegistration .objects .filter (
114
- Q (semester_id__semester_no = sem ) &
115
- Q (course_slot_id = course_slot_object ) &
116
- Q (student_id__batch = batch )
117
- ).values_list ('student_id' , flat = True )
118
-
119
- # Allocate each student directly to FinalRegistration
120
- for student_id in students :
121
- student = Student .objects .get (id = student_id )
122
- semester = Semester .objects .get (semester_no = sem , curriculum = student .batch_id .curriculum )
123
- print (semester .id )
124
- # course = Course.objects.get(id=course_slot_object.courses.id)
125
- course_id = course_slot_object .courses .values_list ('id' , flat = True ).first ()
126
- # Retrieve the Course instance
127
- course = Course .objects .get (id = course_id )
128
-
129
- # Insert directly into FinalRegistration
130
- FinalRegistration .objects .create (
131
- student_id = student ,
132
- verified = False ,
133
- semester_id = semester ,
134
- course_id = course ,
135
- course_slot_id = course_slot_object ,
136
- registration_type = entry ['registration_type' ]
137
- )
138
107
108
+ try :
109
+ with transaction .atomic ():
110
+ for entry in unique_course_slot :
111
+ course_slot_object = CourseSlot .objects .get (
112
+ id = entry ['course_slot_id' ])
113
+ if course_slot_object .type != "Open Elective" :
114
+ # Fetch students registered in this course slot
115
+ students = InitialRegistration .objects .filter (
116
+ Q (semester_id__semester_no = sem ) &
117
+ Q (course_slot_id = course_slot_object ) &
118
+ Q (student_id__batch = batch )
119
+ ).values_list ('student_id' , flat = True )
120
+
121
+ # Allocate each student directly to FinalRegistration
122
+ for student_id in students :
123
+ student = Student .objects .get (id = student_id )
124
+ semester = Semester .objects .get (
125
+ semester_no = sem , curriculum = student .batch_id .curriculum )
126
+ regis = InitialRegistration .objects .filter (
127
+ course_slot_id_id = course_slot_object ,
128
+ student_id_id = student_id
129
+ ).values_list ('registration_type' , flat = True ).first ()
130
+ # course = Course.objects.get(id=course_slot_object.courses.id)
131
+ # course_id = course_slot_object.courses.values_list('id', flat=True).first()
132
+ course_id = InitialRegistration .objects .filter (
133
+ course_slot_id_id = course_slot_object ,
134
+ student_id_id = student_id
135
+ ).values_list ('course_id' , flat = True ).first ()
136
+
137
+ # Retrieve the Course instance
138
+ course = Course .objects .get (id = course_id )
139
+
140
+ # Insert directly into FinalRegistration
141
+ # if course_slot_object.name in unique_course_name:
142
+ # print("skip")
143
+ # continue
144
+
145
+ FinalRegistration .objects .create (
146
+ student_id = student ,
147
+ verified = False ,
148
+ semester_id = semester ,
149
+ course_id = course ,
150
+ course_slot_id = course_slot_object ,
151
+ registration_type = regis
152
+ )
153
+
154
+ unique_course_name .append (course_slot_object .name )
155
+ elif course_slot_object .type == "Open Elective" : # Runs only for open elective course slots
156
+ if course_slot_object .name not in unique_course_name :
157
+ stat = random_algo (batch , sem , year , course_slot_object .name )
139
158
unique_course_name .append (course_slot_object .name )
140
- elif course_slot_object .type == "Open Elective" : # Runs only for open elective course slots
141
- if course_slot_object .name not in unique_course_name :
142
- stat = random_algo (batch ,sem ,year ,course_slot_object .name )
143
- unique_course_name .append (course_slot_object .name )
144
- if (stat == - 1 ) :
145
- print (course_slot_object .name )
146
- raise Exception ("seats not enough for course_slot" + str (course_slot_object .name ))
147
-
148
- return JsonResponse ({'status' : 1 , 'message' : "course allocation successful" })
159
+ if (stat == - 1 ):
160
+ print ("Seats not enough for course_slot" , str (course_slot_object .name ), "terminating process..." )
161
+ raise Exception ("seats not enough for course_slot " + str (course_slot_object .name ))
162
+
163
+ return JsonResponse ({'status' : 1 , 'message' : "course allocation successful" })
149
164
except :
150
- return JsonResponse ({'status' : - 1 , 'message' : "seats not enough for some course_slot" })
165
+ return JsonResponse ({'status' : - 1 , 'message' : "seats not enough for some course_slot" })
151
166
152
167
def view_alloted_course (request ) :
153
168
batch = request .POST .get ('batch' )
0 commit comments