Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server #34

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.env
.vscode
venv
__pycache__
db.sqlite3
db1.sqlite3
__pycache__
migrations
1 change: 0 additions & 1 deletion data.json

This file was deleted.

2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ python manage.py migrate --noinput
python manage.py collectstatic --noinput

# Start server
gunicorn messWebsite.wsgi:application --bind 0.0.0.0:80
gunicorn messWebsite.wsgi:application --bind 0.0.0.0:8000
198 changes: 55 additions & 143 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 All @@ -1039,47 +951,47 @@ class about_Admin(admin.ModelAdmin):
# "description": "%s" % CATERER_BILL_DESC_TEXT,
}

@admin.register(CatererBillsAutumn22)
class about_Admin(ImportExportModelAdmin, admin.ModelAdmin):
resource_class = CatererBillsResource
model = CatererBillsAutumn22
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(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"]
# @admin.register(CatererBillsAutumn22)
# class about_Admin(ImportExportModelAdmin, admin.ModelAdmin):
# resource_class = CatererBillsResource
# model = CatererBillsAutumn22
# 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(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
# 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"
# export_as_csv.short_description = "Export Caterer Bills details to CSV"

@admin.register(CatererBills)
class about_Admin(ImportExportModelAdmin, 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
5 changes: 5 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 Expand Up @@ -147,6 +150,8 @@ class AllocationNewResource(resources.ModelResource):

class Meta:
model = Allocation
exclude="id"
import_id_fields = ["email__name","email_hostel"]
fields = (
"email__roll_no",
"email__email",
Expand Down
23 changes: 15 additions & 8 deletions home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,22 +283,24 @@ def allocation(request):
third_pref=None

# getting period object
if 'Period' in csv_data.columns and 'Semester' in csv_data.columns:
period = str(record["Period"]).capitalize()
semester = str(record["Semester"]).capitalize()
period_obj = Period.objects.get(Sno=period, semester=Semester.objects.get(name=semester))
else:
period_obj = Period.objects.filter().last()
# if 'Period' in csv_data.columns and 'Semester' in csv_data.columns:
# period = str(record["Period"]).capitalize()
# semester = str(record["Semester"]).capitalize()
# period_obj = Period.objects.get(Sno=period, semester=Semester.objects.get(name=semester))
# else:
# period_obj = Period.objects.filter().last()
period_obj = Period.objects.filter().last()

# 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
else:
high_tea=False

student = Student.objects.filter(email=record["Email"]).first()
student = Student.objects.filter(name=record["Name"], hostel=record["Hostel"]).first()
if(student==None):
messages+=str(record["Email"])
print(student)
Expand Down Expand Up @@ -327,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 @@ -430,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 @@ -463,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 @@ -509,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
Loading
Loading