diff --git a/home/migrations/0005_alter_allocation_registration_time.py b/home/migrations/0005_alter_allocation_registration_time.py new file mode 100644 index 0000000..a0c8191 --- /dev/null +++ b/home/migrations/0005_alter_allocation_registration_time.py @@ -0,0 +1,24 @@ +# Generated by Django 5.0.3 on 2024-09-25 14:43 + +import django.utils.timezone +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("home", "0004_allocation_registration_time"), + ] + + operations = [ + migrations.AlterField( + 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", + ), + ), + ] diff --git a/home/signals.py b/home/signals.py index 728bf04..bf5c891 100644 --- a/home/signals.py +++ b/home/signals.py @@ -1,4 +1,5 @@ import logging +from datetime import datetime from django.db.models.signals import post_save, pre_save from django.dispatch import receiver @@ -221,3 +222,22 @@ def create_catererBills(sender, instance, created, **kwargs): caterer=caterer, semester=instance ) caterer_bill.save() + + +@receiver(post_save, sender=Caterer) +def create_catererBills(sender, instance, created, **kwargs): + logger.info("Caterer created:", instance.name) + if created: + for semester in Semester.objects.all(): + end_date = ( + Period.objects.filter(semester=semester) + .order_by("end_date") + .last() + .end_date + ) + if end_date and end_date < datetime.now().date(): + continue + caterer_bill, _ = CatererBills.objects.get_or_create( + caterer=instance, semester=semester + ) + caterer_bill.save() diff --git a/home/views.py b/home/views.py index d1f962b..2bf90eb 100644 --- a/home/views.py +++ b/home/views.py @@ -152,6 +152,8 @@ def rebate(request): """ text = "" list = [] + period_obj = None + allocation_id = None try: student = Student.objects.filter(email__iexact=str(request.user.email)) try: @@ -172,6 +174,10 @@ def rebate(request): except Student.DoesNotExist: key = "Signed in account does not does not have any allocation ID" if request.method == "POST" and request.user.is_authenticated: + if not period_obj or not allocation_id: + text = "You are not allocated for current period, please contact the dining warden to allocate you to a caterer" + request.session["text"] = text + return redirect(request.path) try: start_date = parse_date(request.POST["start_date"]) end_date = parse_date(request.POST["end_date"]) diff --git a/messWebsite/settings.py b/messWebsite/settings.py index af61065..13686a1 100644 --- a/messWebsite/settings.py +++ b/messWebsite/settings.py @@ -18,7 +18,7 @@ SECRET_KEY = env("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = True ALLOWED_HOSTS = ["diningfee.iiti.ac.in", "127.0.0.1", "103.159.214.171"] CSRF_TRUSTED_ORIGINS = ["http://diningfee.iiti.ac.in", "https://diningfee.iiti.ac.in"] @@ -34,7 +34,6 @@ "django.contrib.staticfiles", "django.contrib.sites", "django.contrib.admindocs", - # Third-party apps "import_export", "django_admin_logs", @@ -46,7 +45,6 @@ "cloudinary", "apscheduler", "django_apscheduler", - # Local apps "home.apps.HomeConfig", ]