Skip to content

Commit

Permalink
jain food option available
Browse files Browse the repository at this point in the history
  • Loading branch information
mittal-ishaan committed Sep 21, 2023
1 parent 8da74a9 commit aa4a9e9
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 111 deletions.
1 change: 0 additions & 1 deletion data.json

This file was deleted.

120 changes: 16 additions & 104 deletions home/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,29 +288,6 @@ class about_Admin(admin.ModelAdmin):
# export_as_csv.short_description = "Export Allocation details to CSV"


# # Define the import action
# def import_csv(self, request, queryset):
# # Get the selected file from the request
# file = request.FILES['file']

# # Read the CSV file
# reader = csv.DictReader(file)

# # Loop over each row in the CSV file
# for row in reader:
# # Create a new Book object and save it
# a = Allocatio(
# )
# book.save()

# # Return a success message
# self.message_user(request, 'CSV file imported successfully.')

# import_csv.short_description = 'Import CSV'

# # Override the default actions to include the import action
# actions = [import_csv] + ModelAdmin.actions


@admin.register(Student)
class about_Admin(ImportExportMixin, admin.ModelAdmin):
Expand Down Expand Up @@ -552,6 +529,7 @@ def unregister_student(obj):
period=period,
caterer=caterer,
high_tea=high_tea,
jain=False,
first_pref=caterer,
second_pref=caterer,
third_pref=caterer,
Expand Down Expand Up @@ -895,81 +873,14 @@ def export_as_csv(self, request, queryset):

export_as_csv.short_description = "Export Rebate details to CSV"

allocation_fields = {
"fields": (
"roll_no",
"month",
"student_id",
"caterer_name",
"high_tea",
"first_pref",
"second_pref",
"third_pref",
),
"description": "%s" % ALLOCATION_DESC_TEXT,
}

# @admin.register(AllocationAutumn22)
# class about_Admin(ImportExportModelAdmin, admin.ModelAdmin):
# resource_class = AllocationResource
# model = AllocationAutumn22
# search_fields = ("roll_no__name","roll_no__roll_no","roll_no__hostel","roll_no__email","student_id", "caterer_name", "high_tea")
# list_filter = ("month", "caterer_name", "high_tea","roll_no__hostel","roll_no__degree","roll_no__department",)
# list_display = ("student_id","email", "month", "caterer_name", "high_tea")
# fieldsets = ((None,allocation_fields,),)

# @admin.display(description="email")
# def email(self, obj):
# return obj.roll_no.email

# actions = ["export_as_csv"]

# def export_as_csv(self, request, queryset):
# """
# Export action available in the admin page
# """
# resource = AllocationResource()
# dataset = resource.export(queryset)
# response = HttpResponse(dataset.csv, content_type="text/csv")
# response["Content-Disposition"] = 'attachment; filename="allocation.csv"'
# return response

# export_as_csv.short_description = "Export Allocation details to CSV"

# @admin.register(AllocationSpring23)
# class about_Admin(ImportExportModelAdmin, admin.ModelAdmin):
# resource_class = AllocationResource
# model = AllocationSpring23
# search_fields = ("roll_no__name","roll_no__roll_no","roll_no__hostel","roll_no__email","student_id", "caterer_name", "high_tea",)
# list_filter = ("month", "caterer_name", "high_tea","roll_no__hostel","roll_no__degree","roll_no__department",)
# list_display = ("student_id","email", "month", "caterer_name", "high_tea")
# fieldsets = ((None,allocation_fields,),)

# @admin.display(description="email")
# def email(self, obj):
# return obj.roll_no.email

# actions = ["export_as_csv"]

# def export_as_csv(self, request, queryset):
# """
# Export action available in the admin page
# """
# resource = AllocationResource()
# dataset = resource.export(queryset)
# response = HttpResponse(dataset.csv, content_type="text/csv")
# response["Content-Disposition"] = 'attachment; filename="allocation.csv"'
# return response

# export_as_csv.short_description = "Export Allocation details to CSV"

@admin.register(Allocation)
class about_Admin(ImportExportModelAdmin, admin.ModelAdmin):
resource_class = AllocationNewResource
model = Allocation
search_fields = ("email__name","email__roll_no","email__hostel","email__email","student_id", "caterer__name", "high_tea",)
list_filter = ("period", "caterer", "high_tea","email__hostel","email__degree","email__department",)
list_display = ("student_id","email", "period", "caterer", "high_tea")
list_filter = ("period", "caterer", "high_tea","jain","email__hostel","email__degree","email__department",)
list_display = ("student_id","email", "period", "caterer", "high_tea","jain")
fieldsets = ((None,
{
"fields": (
Expand All @@ -978,6 +889,7 @@ class about_Admin(ImportExportModelAdmin, admin.ModelAdmin):
"student_id",
"caterer",
"high_tea",
"jain",
"first_pref",
"second_pref",
"third_pref",
Expand Down Expand Up @@ -1005,19 +917,19 @@ def export_as_csv(self, request, queryset):
export_as_csv.short_description = "Export Allocation details to CSV"


@admin.register(PeriodAutumn22)
class about_Admin(admin.ModelAdmin):
list_display = ("Sno", "start_date", "end_date")
model = PeriodAutumn22
fieldsets = (
(None,{"fields": ("Sno", "start_date", "end_date")},),)
# @admin.register(PeriodAutumn22)
# class about_Admin(admin.ModelAdmin):
# list_display = ("Sno", "start_date", "end_date")
# model = PeriodAutumn22
# fieldsets = (
# (None,{"fields": ("Sno", "start_date", "end_date")},),)

@admin.register(PeriodSpring23)
class about_Admin(admin.ModelAdmin):
list_display = ("Sno", "start_date", "end_date")
model = PeriodSpring23
fieldsets = (
(None,{"fields": ("Sno", "start_date", "end_date")},),)
# @admin.register(PeriodSpring23)
# class about_Admin(admin.ModelAdmin):
# list_display = ("Sno", "start_date", "end_date")
# model = PeriodSpring23
# fieldsets = (
# (None,{"fields": ("Sno", "start_date", "end_date")},),)

@admin.register(Period)
class about_Admin(admin.ModelAdmin):
Expand Down
4 changes: 4 additions & 0 deletions home/models/allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class Allocation(models.Model):
_("High Tea"), help_text="This contains the info if high tea is taken or not",
default=False,null=True,blank=True
)
jain = models.BooleanField(
_("Jain"), help_text="This contains the info if jain food is taken or not",
default=False,null=True,blank=True
)
first_pref = models.CharField(
_("First Preference"),
default=None,
Expand Down
3 changes: 3 additions & 0 deletions home/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class AllocationResource(resources.ModelResource):
student_id = fields.Field(attribute="student_id", column_name="Student ID")
caterer_name = fields.Field(attribute="caterer_name", column_name="Caterer Allocated")
high_tea = fields.Field(attribute="high_tea", column_name="High Tea")
jain=fields.Field(attribute="jain", column_name="Jain")
first_pref = fields.Field(attribute="first_pref", column_name="First Preferences")
second_pref = fields.Field(
attribute="second_pref", column_name="Second Preferences"
Expand All @@ -97,6 +98,7 @@ class Meta:
"student_id",
"caterer_name",
"high_tea",
"jain",
"first_pref",
"second_pref",
"third_pref",
Expand All @@ -114,6 +116,7 @@ class Meta:
"student_id",
"caterer_name",
"high_tea",
"jain",
"first_pref",
"second_pref",
"third_pref",
Expand Down
8 changes: 7 additions & 1 deletion home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def allocation(request):

# getting high tea
high_tea = record["High Tea"]
jain = record["Jain"]
print(high_tea)
if(high_tea=="Yes" or high_tea==True or high_tea=="TRUE"):
high_tea=True
Expand Down Expand Up @@ -328,6 +329,7 @@ def allocation(request):
period=period_obj,
caterer=caterer,
high_tea=high_tea,
jain=jain,
first_pref=first_pref,
second_pref=second_pref,
third_pref=third_pref,
Expand Down Expand Up @@ -431,6 +433,7 @@ def allocationForm(request):
try:
period_obj = alloc_form.period
high_tea = request.POST["high_tea"]
jain = request.POST["jain"]
if caterer_list.count()<1:
first_pref = None
else:
Expand Down Expand Up @@ -464,13 +467,16 @@ def allocationForm(request):
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,
Expand Down Expand Up @@ -510,7 +516,7 @@ def profile(request):
#improve this alignment of text to be shown on the profile section
if allocation:
allocation_info_list = [allocation.student_id, allocation.caterer.name, str(allocation.high_tea)]
allocation_info = "Allocation ID: " + allocation.student_id + " Caterer: " + allocation.caterer.name + " High Tea: " + str(allocation.high_tea)
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"
if len(socialaccount_obj):
Expand Down
15 changes: 11 additions & 4 deletions templates/allocationForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ <h4 class="px-5 mx-5">
<option value="False">No</option>
</select>
</div>
<div class="form-group p-2">
<label for="high_tea">Jain: </label>
<select class="form-control-sm" id="jain" name="jain">
<option value="True">Yes</option>
<option value="False">No</option>
</select>
</div>
{%if caterer_list.count > 0%}
<div class="form-group p-2">
<label for="Preference1">First Preference: </label>
{%for caterer in caterer_list%}
<div class="form-check form-check-inline">
<label class="form-check-label" for="{{caterer.name}}1">
<input class="form-check-input {{caterer.name}}" type="radio" name="first_pref" id="{{caterer.name}}1" value="{{caterer.name}}">
<input class="form-check-input" type="radio" name="first_pref" id="{{caterer.name}}1" value="{{caterer.name}}">
{{caterer.name}}
</label>
</div>
Expand All @@ -52,7 +59,7 @@ <h4 class="px-5 mx-5">
{%for caterer in caterer_list%}
<div class="form-check form-check-inline">
<label class="form-check-label" for="{{caterer.name}}2">
<input class="form-check-input {{caterer.name}}" type="radio" name="second_pref" id="{{caterer.name}}2" value="{{caterer.name}}">
<input class="form-check-input" type="radio" name="second_pref" id="{{caterer.name}}2" value="{{caterer.name}}">
{{caterer.name}}
</label>
</div>
Expand All @@ -65,7 +72,7 @@ <h4 class="px-5 mx-5">
{%for caterer in caterer_list%}
<div class="form-check form-check-inline">
<label class="form-check-label" for="{{caterer.name}}3">
<input class="form-check-input {{caterer.name}}" type="radio" name="third_pref" id="{{caterer.name}}3" value="{{caterer.name}}">
<input class="form-check-input" type="radio" name="third_pref" id="{{caterer.name}}3" value="{{caterer.name}}">
{{caterer.name}}
</label>
</div>
Expand Down Expand Up @@ -102,7 +109,7 @@ <h4 class="px-5 mx-5">
if(second_pref[i].checked){
cat_list[i]++;
}
if(third_pref.length==first_pref.length && third_pref[i].checked){
if(third_pref.length==3 && third_pref[i].checked){
cat_list[i]++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ <h5 class="text-uppercase mb-mt-4 mb-2 fw-bold text-white">Contact Us</h5>
</div>
</div>
<hr class="">
<div class="row row-cols-md-auto text-center justify-content-between" style="font-size: 12px;">
<div class="row row-cols-md-auto text-center justify-content-between" style="font-size: 14px;">
<div class="col-md-6">
<div class="col-md p-1">Copyright ©2023 All rights reserved by:
<a href="#" class="text-decoration-none">
Expand Down

0 comments on commit aa4a9e9

Please sign in to comment.