Skip to content

Commit 5fb5e63

Browse files
replace generator function and improve creating student id (#110)
1 parent ca7daf8 commit 5fb5e63

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

home/views.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -395,20 +395,17 @@ def allocationForm(request):
395395
caterer_prefs = [
396396
Caterer.objects.get(name=pref) for pref in caterer_prefs if pref
397397
]
398-
399-
caterer = next(
400-
(
401-
c
402-
for c in caterer_prefs
403-
if c.student_limit
404-
> Allocation.objects.filter(caterer=c, period=period_obj).count()
405-
),
406-
None,
407-
)
398+
count_till_now = 0
399+
caterer = None
400+
for c in caterer_prefs:
401+
count_till_now = Allocation.objects.filter(
402+
caterer=c, period=period_obj
403+
).count()
404+
if c.student_limit > count_till_now:
405+
caterer = c
406+
break
408407
if caterer:
409-
student_id = (
410-
f"{caterer.name[0]}{'J' if jain else ''}{caterer.student_limit}"
411-
)
408+
student_id = f"{caterer.name[0]}{'J' if jain else ''}{caterer.student_limit - count_till_now}"
412409
allocation = Allocation(
413410
email=student,
414411
student_id=student_id,

0 commit comments

Comments
 (0)