Skip to content

Commit

Permalink
Added allocation disabling (#107)
Browse files Browse the repository at this point in the history
* Added allocation disabling

* Update in views.py

Co-authored-by: Ishaan Mittal <[email protected]>

---------

Co-authored-by: Ishaan Mittal <[email protected]>
  • Loading branch information
TRISHANT131104 and mittal-ishaan authored Dec 27, 2024
1 parent 16bb809 commit bd8bac4
Show file tree
Hide file tree
Showing 16 changed files with 1,377 additions and 476 deletions.
3 changes: 2 additions & 1 deletion home/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class about_Admin(ImportExportMixin, admin.ModelAdmin):
resource_class = StudentResource
model = Student
search_fields = ("name", "roll_no", "hostel", "degree", "department", "email")
list_display = ("name", "roll_no", "hostel", "email")
list_display = ("name", "roll_no", "hostel", "email", "allocation_enabled")
list_filter = ("hostel", "degree", "department")
fieldsets = (
(
Expand All @@ -261,6 +261,7 @@ class about_Admin(ImportExportMixin, admin.ModelAdmin):
"room_no",
"degree",
"department",
"allocation_enabled"
),
"description": "%s" % STUDENT_DESC_TEXT,
},
Expand Down
1,448 changes: 1,148 additions & 300 deletions home/migrations/0001_initial.py

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions home/migrations/0002_allocation_registration_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.0.10 on 2024-12-26 11:44

import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("home", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="allocation",
name="registration_time",
field=models.DateTimeField(
blank=True,
default=django.utils.timezone.now,
help_text="This contains the date and time of registration",
null=True,
verbose_name="Registration time",
),
),
]
16 changes: 0 additions & 16 deletions home/migrations/0002_delete_todayrebate.py

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions home/migrations/0003_merge_20241117_1607.py

This file was deleted.

21 changes: 21 additions & 0 deletions home/migrations/0003_student_allocation_enabled.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.0.10 on 2024-12-26 12:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("home", "0002_allocation_registration_time"),
]

operations = [
migrations.AddField(
model_name="student",
name="allocation_enabled",
field=models.BooleanField(
default=True,
help_text="Indicates if the student is allowed to participate in the allocation process",
),
),
]
4 changes: 4 additions & 0 deletions home/models/students.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class Student(models.Model):
default="",
blank=True,
)
allocation_enabled = models.BooleanField(
default=True,
help_text="Indicates if the student is allowed to participate in the allocation process"
)

def __str__(self):
return str(self.email)
Expand Down
38 changes: 28 additions & 10 deletions home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ def rebate(request):
allocation = None
try:
student = Student.objects.get(email__iexact=request.user.email)
if not student.allocation_enabled:
message = "You are not eligible to apply for short rebate. For more details, please inquire at the Dining Office."
return render(request, "rebateForm.html", {"text": message})
except Student.DoesNotExist:
message = "Signed in account does not have any allocation ID"
return render(request, "rebateForm.html", {"text": message})
Expand Down Expand Up @@ -252,7 +255,10 @@ def rebate(request):
text = request.session.get("text", "")
if text != "":
del request.session["text"]
context = {"text": text, "key": allocation.student_id}
if not allocation:
context = {"text":text}
else:
context = {"text": text, "key": allocation.student_id}
return render(request, "rebateForm.html", context)


Expand Down Expand Up @@ -293,28 +299,34 @@ def addLongRebateBill(request):
:template:`home/longRebate.html`
Gets the data from the log term rebate form , and adds it to the coresponding rebate bill
This form can only be accessed by the Institute's admin
Gets the data from the long-term rebate form and adds it to the corresponding rebate bill.
This form can only be accessed by the Institute's admin.
"""
text = ""
try:
student = Student.objects.get(email__iexact=request.user.email)
if not student.allocation_enabled:
text = "You are not eligible to apply for long rebate. For more details, please inquire at the Dining Office."
except Student.DoesNotExist:
text = "Email ID does not exist in the database. Please log in using the correct email ID."
return render(request, "longRebate.html", {"text": text})

if request.method == "POST" and request.user.is_authenticated:
try:
start_date = parse_date(request.POST["start_date"])
end_date = parse_date(request.POST["end_date"])
before_rebate_days = (start_date - date.today()).days
days = (end_date - start_date).days + 1
student = Student.objects.get(email__iexact=request.user.email)

if not is_not_duplicate(student, start_date, end_date):
text = "You have already applied for rebate for these dates"
elif before_rebate_days < 2:
text = "Your start date has to be 2 days from todays date"
text = "Your start date has to be 2 days from today's date"
elif days < 0:
text = "Your end date should be after your start date"
else:
# CHANGE THIS TO "FILE NOT UPLOADED".
try:
file = request.FILES["img"]
print(file)
long = LongRebate(
email=student,
start_date=start_date,
Expand All @@ -330,16 +342,20 @@ def addLongRebateBill(request):
logger.error(e)
except Exception as e:
logger.error(e)
text = "Email ID does not exist in the database. Please login using the correct email ID"
text = "An unexpected error occurred. Please try again later."

request.session["text"] = text
return redirect(request.path)
text = request.session.get("text", "")
if text != "":

text = request.session.get("text", text)
if "text" in request.session:
del request.session["text"]

context = {"text": text}
return render(request, "longRebate.html", context)



@login_required
def allocationForm(request):
"""
Expand All @@ -362,6 +378,8 @@ def allocationForm(request):
student = Student.objects.filter(email__iexact=str(request.user.email)).last()
if not student:
message = "Signed in account cannot fill the allocation form. Please inform the dining Office to add your email ID to the database"
elif not student.allocation_enabled:
message = "You are not eligible to fill out this allocation form. For more details, please inquire at the Dining Office."
elif (alloc_form.start_time and alloc_form.start_time > now()) or (
alloc_form.end_time and alloc_form.end_time < now()
):
Expand Down
148 changes: 133 additions & 15 deletions qrscan/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.8 on 2024-10-04 11:03
# Generated by Django 5.0.10 on 2024-12-26 11:42

import django.db.models.deletion
import uuid
Expand All @@ -10,31 +10,149 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('home', '0001_initial'),
("home", "0001_initial"),
]

operations = [
migrations.CreateModel(
name='MessCard',
name="MessTiming",
fields=[
('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)),
('qr_code', models.ImageField(blank=True, help_text='This contains the qr code image', null=True, upload_to='qr_codes/')),
('allocation', models.ForeignKey(blank=True, help_text='This contains the allocation details', null=True, on_delete=django.db.models.deletion.CASCADE, to='home.allocation')),
('student', models.ForeignKey(blank=True, help_text='This contains the student details', null=True, on_delete=django.db.models.deletion.CASCADE, to='home.student')),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"meal_type",
models.CharField(
choices=[
("breakfast", "Breakfast"),
("lunch", "Lunch"),
("high_tea", "High Tea"),
("dinner", "Dinner"),
],
help_text="This contains the meal type",
max_length=10,
unique=True,
),
),
(
"start_time",
models.TimeField(
blank=True, help_text="This contains the start time", null=True
),
),
(
"end_time",
models.TimeField(
blank=True, help_text="This contains the end time", null=True
),
),
],
),
migrations.CreateModel(
name='Meal',
name="MessCard",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateField(auto_now_add=True, help_text='This contains the date of the meal')),
('breakfast', models.BooleanField(default=False, help_text='This contains the breakfast status')),
('lunch', models.BooleanField(default=False, help_text='This contains the lunch status')),
('dinner', models.BooleanField(default=False, help_text='This contains the dinner status')),
('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')),
(
"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,
),
),
(
"qr_code",
models.ImageField(
blank=True,
help_text="This contains the qr code image",
null=True,
upload_to="qr_codes/",
),
),
(
"allocation",
models.ForeignKey(
blank=True,
help_text="This contains the allocation details",
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="home.allocation",
),
),
(
"student",
models.ForeignKey(
help_text="This contains the student details",
on_delete=django.db.models.deletion.CASCADE,
to="home.student",
),
),
],
),
migrations.CreateModel(
name="Meal",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"date",
models.DateField(
auto_now_add=True,
help_text="This contains the date of the meal",
),
),
(
"breakfast",
models.BooleanField(
default=False, help_text="This contains the breakfast status"
),
),
(
"lunch",
models.BooleanField(
default=False, help_text="This contains the lunch status"
),
),
(
"high_tea",
models.BooleanField(
default=False, help_text="This contains the high tea status"
),
),
(
"dinner",
models.BooleanField(
default=False, help_text="This contains the dinner status"
),
),
(
"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",
),
),
],
options={
'unique_together': {('mess_card', 'date')},
"unique_together": {("mess_card", "date")},
},
),
]
Loading

0 comments on commit bd8bac4

Please sign in to comment.