From 0479670945af8102628d71e07c835926e2418982 Mon Sep 17 00:00:00 2001 From: Ishaan Mittal Date: Tue, 7 Nov 2023 19:40:53 +0530 Subject: [PATCH] rebate name added, long rebate query email added --- home/admin.py | 28 +++++++++++++++------------- home/utils/django_email_server.py | 12 ++++++++++++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/home/admin.py b/home/admin.py index 43e4012..47d6a3c 100644 --- a/home/admin.py +++ b/home/admin.py @@ -6,7 +6,7 @@ from django.contrib import admin from django.http import HttpResponse from django.utils.translation import gettext_lazy as _ -from .utils.django_email_server import rebate_mail,caterer_mail +from .utils.django_email_server import rebate_mail,caterer_mail, long_rebate_query_mail from .utils.rebate_bills_saver import save_short_bill, save_long_bill, update_bills from .utils.month import fill_periods from home.models import ( @@ -399,7 +399,7 @@ class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): }, ), ) - actions = ["export_as_csv", "disapprove", "approve"] + actions = ["export_as_csv", "disapprove", "approve","send_mail"] @admin.action(description="Disapprove the students") def disapprove(self, request, queryset): @@ -431,17 +431,13 @@ def export_as_csv(self, request, queryset): export_as_csv.short_description = "Export Rebate details to CSV" - # def save_model(self, request, obj, form, change): - # super().save_model(request, obj, form, change) - # update_bill(instance=obj, sender=obj.__class__, created=change) - - # def save_related(self, request, form, formsets, change): - # super().save_related(request, form, formsets, change) - # print("save related") - # update_bill( - # sender=form.instance.__class__, instance=form.instance, created=change - # ) - + @admin.action(description="Send query mail to the students") + def send_mail(self, request, queryset): + """ + Send mail action available in the admin page + """ + for obj in queryset: + long_rebate_query_mail(obj.start_date, obj.end_date, obj.email.email) @admin.register(Rebate) class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): @@ -459,6 +455,7 @@ class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): list_display = ( "date_applied", "email", + "name", "start_date", "end_date", "approved", @@ -479,6 +476,11 @@ class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): }, ), ) + + @admin.display(description="name") + def name(self, obj): + return obj.email.name + actions = ["export_as_csv", "disapprove", "approve"] @admin.action(description="Disapprove the students") diff --git a/home/utils/django_email_server.py b/home/utils/django_email_server.py index fceef9e..c950c24 100644 --- a/home/utils/django_email_server.py +++ b/home/utils/django_email_server.py @@ -54,6 +54,13 @@ def send_html(subject, message, recipient): left_message = """Note: Bills for {left_start_date} to {left_end_date} will be removed as an when you are allotcated a caterer during this period. """ +message_long_rebate_query = """ +Dear Student, +Your long term rebate application from {start_date} to {end_date} has been recieved but contains some issues. +Kindly send your long rebate application photograph as a reply to this mail itself itself. +""" + + def rebate_mail(start_date, end_date, approved, recipient): subject = subject_rebate if(approved): message = message_rebate.format(start_date=start_date, end_date=end_date, approved = "approved") @@ -75,6 +82,11 @@ def long_rebate_mail(start_date, end_date, approved, recipient, left_start_date, message = message_long_rebate.format(start_date=start_date, end_date=end_date, approved = "rejected",added="added to") send(subject, message, recipient) +def long_rebate_query_mail(start_date, end_date, recipient): + subject = "Long Term Rebate Application Query" + message = message_long_rebate_query.format(start_date=start_date, end_date=end_date) + send(subject, message, recipient) + def __send__rebate__email__(): from datetime import date today = date.today()