From 949559e150a782ea71a47ce6514c55e6920f8d0f Mon Sep 17 00:00:00 2001 From: Ishaan Mittal Date: Sat, 24 Aug 2024 10:44:44 +0530 Subject: [PATCH] Fixes (#73) * update ssl certs docker ignore * few fixes --------- Co-authored-by: Ishaan Mittal --- home/admin.py | 4 ++-- home/views.py | 16 +++++++--------- templates/profile.html | 11 ++++++++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/home/admin.py b/home/admin.py index 3e79b7d..cac27ef 100644 --- a/home/admin.py +++ b/home/admin.py @@ -982,11 +982,11 @@ def get_queryset(self, request): @admin.display(description="email") def email(self, obj): - return obj.email.email + return obj.email.email if obj.email else "" @admin.display(description="name") def name(self, obj): - return obj.email.name + return obj.email.name if obj.email else "" actions = ["export_as_csv", "correct_bills", "fix_issue"] diff --git a/home/views.py b/home/views.py index 625e9d6..b9abdb6 100644 --- a/home/views.py +++ b/home/views.py @@ -363,6 +363,8 @@ def allocationForm(request): alloc_form = AllocationForm.objects.filter(active=True).last() try: student = Student.objects.filter(email__iexact=str(request.user.email)).last() + if not student: + raise Exception("Student not found") text = "" message = "" if (alloc_form.start_time and alloc_form.start_time > now()) or ( @@ -372,13 +374,7 @@ def allocationForm(request): elif Allocation.objects.filter( email=student, period=alloc_form.period ).exists(): - allocation_id = Allocation.objects.filter( - email=student, period=alloc_form.period - ).last() - message = ( - "You have already filled the form for this period. with first preference:" - + allocation_id.first_pref - ) + message = "You have filled the form for this period. Please visit the profile page after the allocation process is completed to check your allocated caterer" elif request.method == "POST" and request.user.is_authenticated: try: period_obj = alloc_form.period @@ -444,8 +440,8 @@ def allocationForm(request): if text != "": del request.session["text"] except Exception as e: - print(e) - message = "Signed in account can not fill the allocation form" + logger.error(e) + message = "Signed in account can not fill the allocation form. Please inform the dining Office to add your email ID to the database" text = "" context = { "text": text, @@ -524,6 +520,8 @@ def rebate_data(request): semester = request.GET.get("semester") semester_obj = Semester.objects.get(name=semester) rebate = StudentBills.objects.filter(email=student, semester=semester_obj).last() + if not rebate: + return JsonResponse({"semester": semester, "period": sno, "data": []}) rebate_bills = get_rebate_bills(rebate, sno) rebate_data = {"semester": semester, "period": sno, "data": rebate_bills} return JsonResponse(rebate_data) diff --git a/templates/profile.html b/templates/profile.html index e749d90..44da9d4 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -34,7 +34,7 @@
{{ key }}
{% endfor %} {% else %} -
You have not been allotted a caterer for this period yet.
+
Your view your allocated caterer once the allocation for this period is completed.
{% endif %}
@@ -123,7 +123,6 @@
Rebate Bills
return; } var semester = $('#semester-select').val(); - console.log(period); $.ajax({ url: "{% url 'rebate_data' %}", type: "GET", @@ -132,8 +131,14 @@
Rebate Bills
'period': period }, success: function(response) { - console.log(response); var data = response.data; + if(data.length == 0) { + $('#short').html(''); + $('#long').html(''); + $('#high_tea').html(''); + $('#bills').html(''); + return; + } var short = document.getElementById('short'); var long = document.getElementById('long'); var high_tea = document.getElementById('high_tea');