diff --git a/home/admin.py b/home/admin.py index 0205e17..27143b8 100644 --- a/home/admin.py +++ b/home/admin.py @@ -36,9 +36,9 @@ Update, ) -from .resources import ( # AllocationResource,; CatererBillsResource, - AllocationNewResource, - CatererBillsNewResource, +from .resources import ( + AllocationResource, + CatererBillsResource, LongRebateResource, RebateBillsResource, RebateResource, @@ -924,7 +924,7 @@ def export_as_csv(self, request, queryset): @admin.register(Allocation) class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): list_per_page = 500 - resource_class = AllocationNewResource + resource_class = AllocationResource model = Allocation search_fields = ( "email__name", @@ -994,7 +994,7 @@ def export_as_csv(self, request, queryset): """ Export action available in the admin page """ - resource = AllocationNewResource() + resource = AllocationResource() dataset = resource.export(queryset) response = HttpResponse(dataset.csv, content_type="text/csv") response["Content-Disposition"] = 'attachment; filename="allocation.csv"' @@ -1049,31 +1049,9 @@ class about_Admin(admin.ModelAdmin): } -# @admin.register(CatererBillsSpring23) -# class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): -# resource_class = CatererBillsResource -# model = CatererBillsSpring23 -# fieldsets = ((None,caterer_bill_fields,),) -# list_display = ("__str__", "period1_bills", "period2_bills", "period3_bills", "period4_bills", "period5_bills", "period6_bills",) -# search_fields = ("caterer__name",) -# actions = ["export_as_csv"] - -# def export_as_csv(self, request, queryset): -# """ -# Export action available in the admin page -# """ -# resource = CatererBillsResource() -# dataset = resource.export(queryset) -# response = HttpResponse(dataset.csv, content_type="text/csv") -# response["Content-Disposition"] = 'attachment; filename="caterer_bills.csv"' -# return response - -# export_as_csv.short_description = "Export Caterer Bills details to CSV" - - @admin.register(CatererBills) class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): - resource_class = CatererBillsNewResource + resource_class = CatererBillsResource model = CatererBills fieldsets = ( ( @@ -1110,7 +1088,7 @@ def export_as_csv(self, request, queryset): """ Export action available in the admin page """ - resource = CatererBillsNewResource() + resource = CatererBillsResource() dataset = resource.export(queryset) response = HttpResponse(dataset.csv, content_type="text/csv") response["Content-Disposition"] = 'attachment; filename="caterer_bills.csv"' diff --git a/home/migrations/0002_remove_allocationautumn23_month_and_more.py b/home/migrations/0002_remove_allocationautumn22_month_and_more.py similarity index 82% rename from home/migrations/0002_remove_allocationautumn23_month_and_more.py rename to home/migrations/0002_remove_allocationautumn22_month_and_more.py index d88a175..93423d9 100644 --- a/home/migrations/0002_remove_allocationautumn23_month_and_more.py +++ b/home/migrations/0002_remove_allocationautumn22_month_and_more.py @@ -1,4 +1,4 @@ -# Generated by Django 5.0.3 on 2024-08-17 14:38 +# Generated by Django 5.0.3 on 2024-08-17 14:53 import django.db.models.deletion from django.db import migrations, models @@ -10,6 +10,14 @@ class Migration(migrations.Migration): ] operations = [ + migrations.RemoveField( + model_name="allocationautumn22", + name="month", + ), + migrations.RemoveField( + model_name="allocationautumn22", + name="roll_no", + ), migrations.RemoveField( model_name="allocationautumn23", name="month", @@ -48,6 +56,10 @@ class Migration(migrations.Migration): model_name="catererbillsspring23", name="caterer", ), + migrations.RemoveField( + model_name="rebateautumn23", + name="email", + ), migrations.AddField( model_name="longrebate", name="reason", @@ -80,12 +92,21 @@ class Migration(migrations.Migration): name="sno", field=models.AutoField(primary_key=True, serialize=False), ), + migrations.DeleteModel( + name="PeriodAutumn22", + ), migrations.DeleteModel( name="AllocationAutumn22", ), + migrations.DeleteModel( + name="PeriodAutumn23", + ), migrations.DeleteModel( name="AllocationAutumn23", ), + migrations.DeleteModel( + name="PeriodSpring23", + ), migrations.DeleteModel( name="AllocationSpring23", ), @@ -98,4 +119,7 @@ class Migration(migrations.Migration): migrations.DeleteModel( name="CatererBillsSpring23", ), + migrations.DeleteModel( + name="RebateAutumn23", + ), ] diff --git a/home/models/Semesters/autumn22.py b/home/models/Semesters/autumn22.py index 376febf..44d8fb5 100644 --- a/home/models/Semesters/autumn22.py +++ b/home/models/Semesters/autumn22.py @@ -4,29 +4,6 @@ from ..students import Student -class PeriodAutumn22(models.Model): - Sno = models.IntegerField( - _("Sno"), default=0, help_text="This contains the serial number of the Period" - ) - start_date = models.DateField( - help_text="This contains the start date of this Period for this semester", - null=True, - blank=True, - ) - end_date = models.DateField( - help_text="This contains the end date of this Period of this semester", - null=True, - blank=True, - ) - - def __str__(self): - return str(self.Sno) - - class Meta: - verbose_name = "Period Details for Autumn 2022" - verbose_name_plural = "Period Details for Autumn 2022" - - class RebateAutumn22(models.Model): """ Storing the Rebate Bills of the Students for the Autumn Semester diff --git a/home/models/Semesters/autumn23.py b/home/models/Semesters/autumn23.py deleted file mode 100644 index 7879bbd..0000000 --- a/home/models/Semesters/autumn23.py +++ /dev/null @@ -1,84 +0,0 @@ -from django.db import models -from django.utils.translation import gettext as _ - -from ..students import Student - - -class PeriodAutumn23(models.Model): - Sno = models.IntegerField( - _("Sno"), default=0, help_text="This contains the serial number of the Period" - ) - start_date = models.DateField( - help_text="This contains the start date of this Period for this semester", - null=True, - blank=True, - ) - end_date = models.DateField( - help_text="This contains the end date of this Period of this semester", - null=True, - blank=True, - ) - - def __str__(self): - return str(self.Sno) - - class Meta: - verbose_name = "Period Details for Autumn 2023" - verbose_name_plural = "Period Details for Autumn 2023" - - -class RebateAutumn23(models.Model): - """ - Storing the Rebate Bills of the Students for the Autumn Semester - """ - - email = models.ForeignKey(Student, on_delete=models.SET_NULL, default="", null=True) - - period1_short = models.IntegerField(_("Period 1 Short"), default=0, null=True) - period1_long = models.IntegerField(_("Period 1 Long"), default=0, null=True) - period1_high_tea = models.BooleanField(_("Period 1 High Tea"), default=True) - period1_bill = models.IntegerField( - _("Period 1 Rebate Amount"), default=0, null=True - ) - - period2_short = models.IntegerField(_("Period 2 Short"), default=0, null=True) - period2_long = models.IntegerField(_("Period 2 Long"), default=0, null=True) - period2_high_tea = models.BooleanField(_("Period 2 High Tea"), default=True) - period2_bill = models.IntegerField( - _("Period 2 Rebate Amount"), default=0, null=True - ) - - period3_short = models.IntegerField(_("Period 3 Short"), default=0, null=True) - period3_long = models.IntegerField(_("Period 3 Long"), default=0, null=True) - period3_high_tea = models.BooleanField(_("Period 3 High Tea"), default=True) - period3_bill = models.IntegerField( - _("Period 3 Rebate Amount"), default=0, null=True - ) - - period4_short = models.IntegerField(_("Period 4 Short"), default=0, null=True) - period4_long = models.IntegerField(_("Period 4 Long"), default=0, null=True) - period4_high_tea = models.BooleanField(_("Period 4 High Tea"), default=True) - period4_bill = models.IntegerField( - _("Period 4 Rebate Amount"), default=0, null=True - ) - - period5_short = models.IntegerField(_("Period 5 Short"), default=0, null=True) - period5_long = models.IntegerField(_("Period 5 Long"), default=0, null=True) - period5_high_tea = models.BooleanField(_("Period 5 High Tea"), default=True) - period5_bill = models.IntegerField( - _("Period 5 Rebate Amount"), default=0, null=True - ) - - period6_short = models.IntegerField(_("Period 6 Short"), default=0, null=True) - period6_long = models.IntegerField(_("Period 6 Long"), default=0, null=True) - period6_high_tea = models.BooleanField(_("Period 6 High Tea"), default=True) - period6_bill = models.IntegerField( - _("Period 6 Rebate Amount"), default=0, null=True - ) - - def __str__(self): - return str(self.email.email) - - class Meta: - verbose_name = "Rebate Bill Autumn 2023" - verbose_name_plural = "Rebate Bills Autumn 2023" diff --git a/home/models/Semesters/spring23.py b/home/models/Semesters/spring23.py index fea4fe0..c56e5c6 100644 --- a/home/models/Semesters/spring23.py +++ b/home/models/Semesters/spring23.py @@ -4,29 +4,6 @@ from ..students import Student -class PeriodSpring23(models.Model): - Sno = models.IntegerField( - _("Sno"), default=0, help_text="This contains the serial number of the Period" - ) - start_date = models.DateField( - help_text="This contains the start date of this Period for this semester", - null=True, - blank=True, - ) - end_date = models.DateField( - help_text="This contains the end date of this Period of this semester", - null=True, - blank=True, - ) - - def __str__(self): - return str(self.Sno) - - class Meta: - verbose_name = "Period Details for Spring 2023" - verbose_name_plural = "Period Details for Spring 2023" - - class RebateSpring23(models.Model): """ Storing the Rebate Bills of the Students for the Spring Semester diff --git a/home/models/__init__.py b/home/models/__init__.py index b71c419..1ac6463 100644 --- a/home/models/__init__.py +++ b/home/models/__init__.py @@ -10,15 +10,9 @@ from .links import Form from .rules import Rule, ShortRebate from .Semesters.autumn22 import ( - PeriodAutumn22, RebateAutumn22, ) -from .Semesters.autumn23 import ( - PeriodAutumn23, - RebateAutumn23, -) from .Semesters.spring23 import ( - PeriodSpring23, RebateSpring23, ) from .students import ( diff --git a/home/resources.py b/home/resources.py index 1eff824..eee6281 100644 --- a/home/resources.py +++ b/home/resources.py @@ -19,7 +19,6 @@ """ File-name: resources.py Functions: StudentResource - AllocationResource RebateResource RebateSpringResource RebateAutumnResource @@ -55,7 +54,7 @@ class Meta: ) -class AllocationNewResource(resources.ModelResource): +class AllocationResource(resources.ModelResource): email__roll_no = fields.Field(attribute="email__roll_no", column_name="Roll No.") email__email = fields.Field(attribute="email__email", column_name="Email") email__name = fields.Field(attribute="email__name", column_name="Name") @@ -749,7 +748,7 @@ class Meta: fields = ("email",) -class CatererBillsNewResource(resources.ModelResource): +class CatererBillsResource(resources.ModelResource): caterer__name = fields.Field(attribute="caterer__name", column_name="Caterer") semester__name = fields.Field(attribute="semester__name", column_name="Semester") period1_bills = fields.Field( diff --git a/home/utils/get_rebate_bills.py b/home/utils/get_rebate_bills.py index 4406eee..51ef619 100644 --- a/home/utils/get_rebate_bills.py +++ b/home/utils/get_rebate_bills.py @@ -1,4 +1,4 @@ -def get_rebate_bills(rebate, period): +def get_rebate_bills(rebate, period: int): period = int(period) if period == 1: short = rebate.period1_short diff --git a/home/views.py b/home/views.py index 3f1e840..7aae9c3 100644 --- a/home/views.py +++ b/home/views.py @@ -21,11 +21,7 @@ LeftShortRebate, LongRebate, Period, - PeriodAutumn22, - PeriodSpring23, Rebate, - RebateAutumn22, - RebateSpring23, Rule, Semester, ShortRebate, @@ -508,13 +504,8 @@ def profile(request): def period_data(request): print("period_data") name = request.GET.get("semester") - if name == "autumn22": - period = PeriodAutumn22.objects.all() - elif name == "spring23": - period = PeriodSpring23.objects.all() - else: - semester = Semester.objects.get(name=name) - period = Period.objects.filter(semester=semester) + semester = Semester.objects.get(name=name) + period = Period.objects.filter(semester=semester) period_data = { "semester": name, "data": list(period.values("Sno", "start_date", "end_date")), @@ -529,17 +520,8 @@ def rebate_data(request): student = Student.objects.get(email__iexact=user.email) sno = request.GET.get("period") semester = request.GET.get("semester") - if semester == "autumn22": - rebate = RebateAutumn22.objects.filter(email=student).last() - rebate_bills = get_rebate_bills(rebate, sno) - elif semester == "spring23": - rebate = RebateSpring23.objects.filter(email=student).last() - rebate_bills = get_rebate_bills(rebate, sno) - else: - semester_obj = Semester.objects.get(name=semester) - rebate = StudentBills.objects.filter( - email=student, semester=semester_obj - ).last() - rebate_bills = get_rebate_bills(rebate, sno) + semester_obj = Semester.objects.get(name=semester) + rebate = StudentBills.objects.filter(email=student, semester=semester_obj).last() + rebate_bills = get_rebate_bills(rebate, sno) rebate_data = {"semester": semester, "period": sno, "data": rebate_bills} return JsonResponse(rebate_data)