Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaan-tf committed Aug 17, 2024
1 parent e36b56d commit ce6f263
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 193 deletions.
36 changes: 7 additions & 29 deletions home/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
Update,
)

from .resources import ( # AllocationResource,; CatererBillsResource,
AllocationNewResource,
CatererBillsNewResource,
from .resources import (
AllocationResource,
CatererBillsResource,
LongRebateResource,
RebateBillsResource,
RebateResource,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"'
Expand Down Expand Up @@ -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 = (
(
Expand Down Expand Up @@ -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"'
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
),
Expand All @@ -98,4 +119,7 @@ class Migration(migrations.Migration):
migrations.DeleteModel(
name="CatererBillsSpring23",
),
migrations.DeleteModel(
name="RebateAutumn23",
),
]
23 changes: 0 additions & 23 deletions home/models/Semesters/autumn22.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
84 changes: 0 additions & 84 deletions home/models/Semesters/autumn23.py

This file was deleted.

23 changes: 0 additions & 23 deletions home/models/Semesters/spring23.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions home/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
5 changes: 2 additions & 3 deletions home/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"""
File-name: resources.py
Functions: StudentResource
AllocationResource
RebateResource
RebateSpringResource
RebateAutumnResource
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion home/utils/get_rebate_bills.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 5 additions & 23 deletions home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
LeftShortRebate,
LongRebate,
Period,
PeriodAutumn22,
PeriodSpring23,
Rebate,
RebateAutumn22,
RebateSpring23,
Rule,
Semester,
ShortRebate,
Expand Down Expand Up @@ -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")),
Expand All @@ -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)

0 comments on commit ce6f263

Please sign in to comment.