From 981fa48309032e0ccfe1a56246a3eb9a552f29a9 Mon Sep 17 00:00:00 2001 From: Ishaan Mittal Date: Sat, 24 Aug 2024 10:08:01 +0530 Subject: [PATCH 1/4] update ssl certs docker ignore --- .gitignore | 1 + nginx/.dockerignore | 1 + 2 files changed, 2 insertions(+) create mode 100644 nginx/.dockerignore diff --git a/.gitignore b/.gitignore index 699b170..92bf975 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ venv .venv media staticfiles +ssl-certs diff --git a/nginx/.dockerignore b/nginx/.dockerignore new file mode 100644 index 0000000..4a966b5 --- /dev/null +++ b/nginx/.dockerignore @@ -0,0 +1 @@ +!ssl-certs/ From 12b41e2b175719bd0d96b89eeb5c762d7f0637b2 Mon Sep 17 00:00:00 2001 From: Ishaan Mittal Date: Sat, 24 Aug 2024 10:43:20 +0530 Subject: [PATCH 2/4] few fixes --- 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'); From bd34fc9f274dd5af13a7217632aeb3e11b40a220 Mon Sep 17 00:00:00 2001 From: Ishaan Mittal Date: Sat, 24 Aug 2024 11:51:10 +0530 Subject: [PATCH 3/4] quick fix --- home/admin.py | 1 + .../0003_allocationform_show_allocated.py | 17 +++++++++++++++++ home/models/students.py | 1 + home/views.py | 16 +++++++++------- templates/profile.html | 2 +- 5 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 home/migrations/0003_allocationform_show_allocated.py diff --git a/home/admin.py b/home/admin.py index cac27ef..a78a8ef 100644 --- a/home/admin.py +++ b/home/admin.py @@ -1203,6 +1203,7 @@ class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): "start_time", "end_time", "active", + "show_allocated", ) }, ), diff --git a/home/migrations/0003_allocationform_show_allocated.py b/home/migrations/0003_allocationform_show_allocated.py new file mode 100644 index 0000000..1c06dd1 --- /dev/null +++ b/home/migrations/0003_allocationform_show_allocated.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0.3 on 2024-08-24 05:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("home", "0002_remove_allocationautumn22_month_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="allocationform", + name="show_allocated", + field=models.BooleanField(default=False, verbose_name="show_allocated"), + ), + ] diff --git a/home/models/students.py b/home/models/students.py index 5331e1b..67ffaec 100644 --- a/home/models/students.py +++ b/home/models/students.py @@ -272,6 +272,7 @@ class AllocationForm(models.Model): _("Start Time"), default=now, null=True, blank=True ) end_time = models.DateTimeField(_("End Time"), null=True, blank=True) + show_allocated = models.BooleanField(_("show_allocated"), default=False) def __str__(self): return str(self.heading) diff --git a/home/views.py b/home/views.py index b9abdb6..a6f5b03 100644 --- a/home/views.py +++ b/home/views.py @@ -467,19 +467,21 @@ def profile(request): provider="google", user_id=request.user.id ) picture = "not available" - allocation = Allocation.objects.filter(email=student).last() + allocation: Allocation | None = Allocation.objects.filter(email=student).last() + show_allocated_enabled = AllocationForm.objects.filter( + show_allocated=True, period=allocation.period + ).exists() allocation_info = {} # improve this alignment of text to be shown on the profile section - if allocation: + if allocation and show_allocated_enabled: allocation_info = { - "Allocation ID": allocation.student_id, + "start date": allocation.period.start_date, + "end date": allocation.period.end_date, + # "Allocation ID": allocation.student_id, "Caterer": allocation.caterer.name, - "High Tea": "Yes" if allocation.high_tea else "No", + # "High Tea": "Yes" if allocation.high_tea else "No", "Jain": "Yes" if allocation.jain else "No", } - # allocation_info = "Allocation ID: " + allocation.student_id + " Caterer: " + allocation.caterer.name + " High Tea: " + str(allocation.high_tea) + " Jain: " + str(allocation.jain) - # else: - # allocation_info = "Not allocated for this period" try: if socialaccount_obj: picture = socialaccount_obj[0].extra_data["picture"] diff --git a/templates/profile.html b/templates/profile.html index 44da9d4..1b93e59 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -34,7 +34,7 @@
{{ key }}
{% endfor %} {% else %} -
Your view your allocated caterer once the allocation for this period is completed.
+
You will be able to see your allocated caterer after the allocation process is completed
{% endif %}
From 188419d421a077e6e06de78d5b6cb4a3edb84eea Mon Sep 17 00:00:00 2001 From: Ishaan Mittal Date: Sun, 25 Aug 2024 03:26:50 +0530 Subject: [PATCH 4/4] few fixes --- home/views.py | 126 +++++++++++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 62 deletions(-) diff --git a/home/views.py b/home/views.py index a6f5b03..58d4ba9 100644 --- a/home/views.py +++ b/home/views.py @@ -362,78 +362,80 @@ def allocationForm(request): caterer_list = Caterer.objects.filter(visible=True).all() alloc_form = AllocationForm.objects.filter(active=True).last() try: + if not alloc_form: + raise Exception("Form is closed for now") student = Student.objects.filter(email__iexact=str(request.user.email)).last() if not student: - raise Exception("Student not found") + raise Exception( + "Signed in account can not fill the allocation form. Please inform the dining Office to add your email ID to the database" + ) text = "" message = "" if (alloc_form.start_time and alloc_form.start_time > now()) or ( alloc_form.end_time and alloc_form.end_time < now() ): - message = "Form is closed for now." + raise Exception("The Form is closed for now") elif Allocation.objects.filter( email=student, period=alloc_form.period ).exists(): - 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" + raise Exception( + "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 - high_tea = False - jain = request.POST["jain"] - if jain == "True": - high_tea = False - if caterer_list.count() < 1: - first_pref = None - else: - first_pref = request.POST["first_pref"] - caterer1 = Caterer.objects.get(name=first_pref) - if caterer_list.count() < 2: - second_pref = None - else: - second_pref = request.POST["second_pref"] - caterer2 = Caterer.objects.get(name=second_pref) - if caterer_list.count() < 3: - third_pref = None - else: - third_pref = request.POST["third_pref"] - caterer3 = Caterer.objects.get(name=third_pref) - if caterer1.student_limit > 0: - caterer1.student_limit -= 1 - caterer1.save(update_fields=["student_limit"]) - caterer = caterer1 - elif caterer2 and caterer2.student_limit > 0: - caterer2.student_limit -= 1 - caterer2.save(update_fields=["student_limit"]) - caterer = caterer2 - elif caterer3 and caterer3.student_limit > 0: - caterer3.student_limit -= 1 - caterer3.save(update_fields=["student_limit"]) - caterer = caterer3 - student_id = str(caterer.name[0]) - # if high_tea == "True": - # student_id += "H" - # else: - # student_id+="NH" - if jain == "True": - student_id += "J" - student_id += str(caterer.student_limit) - allocation = Allocation( - email=student, - student_id=student_id, - period=period_obj, - caterer=caterer, - high_tea=high_tea, - jain=jain, - first_pref=first_pref, - second_pref=second_pref, - third_pref=third_pref, - ) - allocation.save() - UnregisteredStudent.objects.filter(email__iexact=student.email).delete() - text = "Allocation Form filled Successfully" - except Exception as e: - message = "The Form is closed for now" - print(e) + period_obj = alloc_form.period + high_tea = False + jain = request.POST["jain"] + # if jain == "True": + # high_tea = False + if caterer_list.count() < 1: + first_pref = None + else: + first_pref = request.POST["first_pref"] + caterer1 = Caterer.objects.get(name=first_pref) + if caterer_list.count() < 2: + second_pref = None + else: + second_pref = request.POST["second_pref"] + caterer2 = Caterer.objects.get(name=second_pref) + if caterer_list.count() < 3: + third_pref = None + else: + third_pref = request.POST["third_pref"] + caterer3 = Caterer.objects.get(name=third_pref) + if caterer1.student_limit > 0: + caterer1.student_limit -= 1 + caterer1.save(update_fields=["student_limit"]) + caterer = caterer1 + elif caterer2 and caterer2.student_limit > 0: + caterer2.student_limit -= 1 + caterer2.save(update_fields=["student_limit"]) + caterer = caterer2 + elif caterer3 and caterer3.student_limit > 0: + caterer3.student_limit -= 1 + caterer3.save(update_fields=["student_limit"]) + caterer = caterer3 + student_id = str(caterer.name[0]) + # if high_tea == "True": + # student_id += "H" + # else: + # student_id+="NH" + if jain == "True": + student_id += "J" + student_id += str(caterer.student_limit) + allocation = Allocation( + email=student, + student_id=student_id, + period=period_obj, + caterer=caterer, + high_tea=high_tea, + jain=jain, + first_pref=first_pref, + second_pref=second_pref, + third_pref=third_pref, + ) + allocation.save() + UnregisteredStudent.objects.filter(email__iexact=student.email).delete() + text = "Allocation Form filled Successfully" request.session["text"] = text return redirect(request.path) text = request.session.get("text", "") @@ -441,7 +443,7 @@ def allocationForm(request): del request.session["text"] except Exception as e: 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" + message = e text = "" context = { "text": text,