Skip to content

Commit bd8bac4

Browse files
Added allocation disabling (#107)
* Added allocation disabling * Update in views.py Co-authored-by: Ishaan Mittal <ishaanmittal123@gmail.com> --------- Co-authored-by: Ishaan Mittal <ishaanmittal123@gmail.com>
1 parent 16bb809 commit bd8bac4

16 files changed

Lines changed: 1377 additions & 476 deletions

home/admin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class about_Admin(ImportExportMixin, admin.ModelAdmin):
247247
resource_class = StudentResource
248248
model = Student
249249
search_fields = ("name", "roll_no", "hostel", "degree", "department", "email")
250-
list_display = ("name", "roll_no", "hostel", "email")
250+
list_display = ("name", "roll_no", "hostel", "email", "allocation_enabled")
251251
list_filter = ("hostel", "degree", "department")
252252
fieldsets = (
253253
(
@@ -261,6 +261,7 @@ class about_Admin(ImportExportMixin, admin.ModelAdmin):
261261
"room_no",
262262
"degree",
263263
"department",
264+
"allocation_enabled"
264265
),
265266
"description": "%s" % STUDENT_DESC_TEXT,
266267
},

home/migrations/0001_initial.py

Lines changed: 1148 additions & 300 deletions
Large diffs are not rendered by default.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated by Django 5.0.10 on 2024-12-26 11:44
2+
3+
import django.utils.timezone
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("home", "0001_initial"),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name="allocation",
16+
name="registration_time",
17+
field=models.DateTimeField(
18+
blank=True,
19+
default=django.utils.timezone.now,
20+
help_text="This contains the date and time of registration",
21+
null=True,
22+
verbose_name="Registration time",
23+
),
24+
),
25+
]

home/migrations/0002_delete_todayrebate.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

home/migrations/0002_remove_rebatespring23_email_delete_rebateautumn22_and_more.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

home/migrations/0003_merge_20241117_1607.py

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Django 5.0.10 on 2024-12-26 12:21
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("home", "0002_allocation_registration_time"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="student",
15+
name="allocation_enabled",
16+
field=models.BooleanField(
17+
default=True,
18+
help_text="Indicates if the student is allowed to participate in the allocation process",
19+
),
20+
),
21+
]

home/models/students.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class Student(models.Model):
5757
default="",
5858
blank=True,
5959
)
60+
allocation_enabled = models.BooleanField(
61+
default=True,
62+
help_text="Indicates if the student is allowed to participate in the allocation process"
63+
)
6064

6165
def __str__(self):
6266
return str(self.email)

home/views.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ def rebate(request):
156156
allocation = None
157157
try:
158158
student = Student.objects.get(email__iexact=request.user.email)
159+
if not student.allocation_enabled:
160+
message = "You are not eligible to apply for short rebate. For more details, please inquire at the Dining Office."
161+
return render(request, "rebateForm.html", {"text": message})
159162
except Student.DoesNotExist:
160163
message = "Signed in account does not have any allocation ID"
161164
return render(request, "rebateForm.html", {"text": message})
@@ -252,7 +255,10 @@ def rebate(request):
252255
text = request.session.get("text", "")
253256
if text != "":
254257
del request.session["text"]
255-
context = {"text": text, "key": allocation.student_id}
258+
if not allocation:
259+
context = {"text":text}
260+
else:
261+
context = {"text": text, "key": allocation.student_id}
256262
return render(request, "rebateForm.html", context)
257263

258264

@@ -293,28 +299,34 @@ def addLongRebateBill(request):
293299
294300
:template:`home/longRebate.html`
295301
296-
Gets the data from the log term rebate form , and adds it to the coresponding rebate bill
297-
This form can only be accessed by the Institute's admin
302+
Gets the data from the long-term rebate form and adds it to the corresponding rebate bill.
303+
This form can only be accessed by the Institute's admin.
298304
"""
299305
text = ""
306+
try:
307+
student = Student.objects.get(email__iexact=request.user.email)
308+
if not student.allocation_enabled:
309+
text = "You are not eligible to apply for long rebate. For more details, please inquire at the Dining Office."
310+
except Student.DoesNotExist:
311+
text = "Email ID does not exist in the database. Please log in using the correct email ID."
312+
return render(request, "longRebate.html", {"text": text})
313+
300314
if request.method == "POST" and request.user.is_authenticated:
301315
try:
302316
start_date = parse_date(request.POST["start_date"])
303317
end_date = parse_date(request.POST["end_date"])
304318
before_rebate_days = (start_date - date.today()).days
305319
days = (end_date - start_date).days + 1
306-
student = Student.objects.get(email__iexact=request.user.email)
320+
307321
if not is_not_duplicate(student, start_date, end_date):
308322
text = "You have already applied for rebate for these dates"
309323
elif before_rebate_days < 2:
310-
text = "Your start date has to be 2 days from todays date"
324+
text = "Your start date has to be 2 days from today's date"
311325
elif days < 0:
312326
text = "Your end date should be after your start date"
313327
else:
314-
# CHANGE THIS TO "FILE NOT UPLOADED".
315328
try:
316329
file = request.FILES["img"]
317-
print(file)
318330
long = LongRebate(
319331
email=student,
320332
start_date=start_date,
@@ -330,16 +342,20 @@ def addLongRebateBill(request):
330342
logger.error(e)
331343
except Exception as e:
332344
logger.error(e)
333-
text = "Email ID does not exist in the database. Please login using the correct email ID"
345+
text = "An unexpected error occurred. Please try again later."
346+
334347
request.session["text"] = text
335348
return redirect(request.path)
336-
text = request.session.get("text", "")
337-
if text != "":
349+
350+
text = request.session.get("text", text)
351+
if "text" in request.session:
338352
del request.session["text"]
353+
339354
context = {"text": text}
340355
return render(request, "longRebate.html", context)
341356

342357

358+
343359
@login_required
344360
def allocationForm(request):
345361
"""
@@ -362,6 +378,8 @@ def allocationForm(request):
362378
student = Student.objects.filter(email__iexact=str(request.user.email)).last()
363379
if not student:
364380
message = "Signed in account cannot fill the allocation form. Please inform the dining Office to add your email ID to the database"
381+
elif not student.allocation_enabled:
382+
message = "You are not eligible to fill out this allocation form. For more details, please inquire at the Dining Office."
365383
elif (alloc_form.start_time and alloc_form.start_time > now()) or (
366384
alloc_form.end_time and alloc_form.end_time < now()
367385
):

qrscan/migrations/0001_initial.py

Lines changed: 133 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 5.0.8 on 2024-10-04 11:03
1+
# Generated by Django 5.0.10 on 2024-12-26 11:42
22

33
import django.db.models.deletion
44
import uuid
@@ -10,31 +10,149 @@ class Migration(migrations.Migration):
1010
initial = True
1111

1212
dependencies = [
13-
('home', '0001_initial'),
13+
("home", "0001_initial"),
1414
]
1515

1616
operations = [
1717
migrations.CreateModel(
18-
name='MessCard',
18+
name="MessTiming",
1919
fields=[
20-
('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='This contains the unique id of the mess card', primary_key=True, serialize=False, unique=True)),
21-
('qr_code', models.ImageField(blank=True, help_text='This contains the qr code image', null=True, upload_to='qr_codes/')),
22-
('allocation', models.ForeignKey(blank=True, help_text='This contains the allocation details', null=True, on_delete=django.db.models.deletion.CASCADE, to='home.allocation')),
23-
('student', models.ForeignKey(blank=True, help_text='This contains the student details', null=True, on_delete=django.db.models.deletion.CASCADE, to='home.student')),
20+
(
21+
"id",
22+
models.BigAutoField(
23+
auto_created=True,
24+
primary_key=True,
25+
serialize=False,
26+
verbose_name="ID",
27+
),
28+
),
29+
(
30+
"meal_type",
31+
models.CharField(
32+
choices=[
33+
("breakfast", "Breakfast"),
34+
("lunch", "Lunch"),
35+
("high_tea", "High Tea"),
36+
("dinner", "Dinner"),
37+
],
38+
help_text="This contains the meal type",
39+
max_length=10,
40+
unique=True,
41+
),
42+
),
43+
(
44+
"start_time",
45+
models.TimeField(
46+
blank=True, help_text="This contains the start time", null=True
47+
),
48+
),
49+
(
50+
"end_time",
51+
models.TimeField(
52+
blank=True, help_text="This contains the end time", null=True
53+
),
54+
),
2455
],
2556
),
2657
migrations.CreateModel(
27-
name='Meal',
58+
name="MessCard",
2859
fields=[
29-
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
30-
('date', models.DateField(auto_now_add=True, help_text='This contains the date of the meal')),
31-
('breakfast', models.BooleanField(default=False, help_text='This contains the breakfast status')),
32-
('lunch', models.BooleanField(default=False, help_text='This contains the lunch status')),
33-
('dinner', models.BooleanField(default=False, help_text='This contains the dinner status')),
34-
('mess_card', models.ForeignKey(blank=True, help_text='This contains the mess card details', null=True, on_delete=django.db.models.deletion.CASCADE, to='qrscan.messcard')),
60+
(
61+
"id",
62+
models.UUIDField(
63+
default=uuid.uuid4,
64+
editable=False,
65+
help_text="This contains the unique id of the mess card",
66+
primary_key=True,
67+
serialize=False,
68+
unique=True,
69+
),
70+
),
71+
(
72+
"qr_code",
73+
models.ImageField(
74+
blank=True,
75+
help_text="This contains the qr code image",
76+
null=True,
77+
upload_to="qr_codes/",
78+
),
79+
),
80+
(
81+
"allocation",
82+
models.ForeignKey(
83+
blank=True,
84+
help_text="This contains the allocation details",
85+
null=True,
86+
on_delete=django.db.models.deletion.CASCADE,
87+
to="home.allocation",
88+
),
89+
),
90+
(
91+
"student",
92+
models.ForeignKey(
93+
help_text="This contains the student details",
94+
on_delete=django.db.models.deletion.CASCADE,
95+
to="home.student",
96+
),
97+
),
98+
],
99+
),
100+
migrations.CreateModel(
101+
name="Meal",
102+
fields=[
103+
(
104+
"id",
105+
models.BigAutoField(
106+
auto_created=True,
107+
primary_key=True,
108+
serialize=False,
109+
verbose_name="ID",
110+
),
111+
),
112+
(
113+
"date",
114+
models.DateField(
115+
auto_now_add=True,
116+
help_text="This contains the date of the meal",
117+
),
118+
),
119+
(
120+
"breakfast",
121+
models.BooleanField(
122+
default=False, help_text="This contains the breakfast status"
123+
),
124+
),
125+
(
126+
"lunch",
127+
models.BooleanField(
128+
default=False, help_text="This contains the lunch status"
129+
),
130+
),
131+
(
132+
"high_tea",
133+
models.BooleanField(
134+
default=False, help_text="This contains the high tea status"
135+
),
136+
),
137+
(
138+
"dinner",
139+
models.BooleanField(
140+
default=False, help_text="This contains the dinner status"
141+
),
142+
),
143+
(
144+
"mess_card",
145+
models.ForeignKey(
146+
blank=True,
147+
help_text="This contains the mess card details",
148+
null=True,
149+
on_delete=django.db.models.deletion.CASCADE,
150+
to="qrscan.messcard",
151+
),
152+
),
35153
],
36154
options={
37-
'unique_together': {('mess_card', 'date')},
155+
"unique_together": {("mess_card", "date")},
38156
},
39157
),
40158
]

0 commit comments

Comments
 (0)