Skip to content

Commit ef8ccb8

Browse files
authored
Merge pull request #1857 from vikrantwiz02/prod/acad-react
Included programme_type in Random Allocation
2 parents 402276a + ee652db commit ef8ccb8

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

FusionIIIT/applications/academic_information/api/views.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,14 @@ def spi_api(request):
253253
@role_required(['acadadmin'])
254254
def check_allocation_api(request):
255255
"""
256-
API to check the allocation status for a given batch, semester, and year.
256+
API to check the allocation status for a given batch, semester, year, and programme_type.
257257
Uses the utility function to avoid code repetition.
258258
"""
259259
try:
260260
batch = request.data.get('batch')
261261
sem = request.data.get('sem')
262262
year = request.data.get('year')
263+
programme_type = request.data.get('programme_type')
263264

264265
if not batch or not sem or not year:
265266
return Response(
@@ -276,7 +277,7 @@ def check_allocation_api(request):
276277
status=status.HTTP_400_BAD_REQUEST
277278
)
278279

279-
result = check_for_registration_complete(batch, sem, year)
280+
result = check_for_registration_complete(batch, sem, year, programme_type)
280281

281282
# Map status values to appropriate HTTP codes
282283
status_code_map = {
@@ -308,6 +309,7 @@ def start_allocation_api(request):
308309
batch = data.get("batch")
309310
semester = data.get("semester")
310311
year = data.get("year")
312+
programme_type = data.get("programme_type")
311313

312314
if not batch or not semester or not year:
313315
return JsonResponse({"error": "Missing required fields"}, status=400)
@@ -316,7 +318,7 @@ def start_allocation_api(request):
316318
semester = int(semester)
317319

318320
mock_request = type('MockRequest', (), {})()
319-
mock_request.POST = {'batch': batch, 'sem': semester, 'year': year}
321+
mock_request.POST = {'batch': batch, 'sem': semester, 'year': year, 'programme_type': programme_type}
320322

321323
return allocate(mock_request)
322324

@@ -386,7 +388,7 @@ def generate_xlsheet_api(request):
386388
u.first_name,
387389
u.last_name,
388390
CONCAT(u.first_name, ' ', u.last_name) as full_name,
389-
COALESCE(s.specialization, 'General') as discipline,
391+
COALESCE(d.acronym, 'General') as discipline,
390392
u.email,
391393
cr.registration_type,
392394
c.code as course_code,
@@ -396,6 +398,8 @@ def generate_xlsheet_api(request):
396398
INNER JOIN globals_extrainfo ei ON cr.student_id_id = ei.id
397399
INNER JOIN auth_user u ON ei.user_id = u.id
398400
LEFT JOIN academic_information_student s ON ei.id = s.id_id
401+
LEFT JOIN programme_curriculum_batch b ON s.batch_id_id = b.id
402+
LEFT JOIN programme_curriculum_discipline d ON b.discipline_id = d.id
399403
INNER JOIN programme_curriculum_course c ON cr.course_id_id = c.id
400404
WHERE cr.session = %s
401405
AND cr.semester_type = %s

FusionIIIT/applications/academic_information/utils.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import random
1616
from django.db import transaction
1717
time = 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

Comments
 (0)