Skip to content

Commit

Permalink
Merge pull request #41 from DaemonLab/server-trishant
Browse files Browse the repository at this point in the history
Server trishant
  • Loading branch information
mittal-ishaan authored Oct 10, 2023
2 parents ae1658f + 5ae4c11 commit 86db307
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 24 deletions.
37 changes: 15 additions & 22 deletions home/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class about_Admin(admin.ModelAdmin):
{
"fields": (
"name",
"email",
"upper_description",
"sheet_url",
"lower_description",
Expand Down Expand Up @@ -609,29 +610,21 @@ class about_Admin(ImportExportModelAdmin, admin.ModelAdmin):

@admin.action(description="Send mail to the caterer")
def send_mail(self, request, queryset):
"""
Send mail action available in the admin page
"""
from datetime import date
today = date.today()
text = "<li> {name} with {allocation_id} has applied from {start_date} to {end_date}</li>"
messageKanaka=""
messageGauri=""
messageAjay=""
date = queryset[0].date
for obj in queryset:
allocation=obj.allocation_id
if(obj.Caterer == "Kanaka"):
messageKanaka +=(text.format(allocation_id=allocation.student_id,name=allocation.email.name, start_date=obj.start_date, end_date=obj.end_date))
elif(obj.Caterer == "Gauri"):
messageGauri +=(text.format(allocation_id=allocation.student_id,name=allocation.email.name, start_date=obj.start_date, end_date=obj.end_date))
elif(obj.Caterer == "Ajay"):
messageAjay +=(text.format(allocation_id=allocation.student_id,name=allocation.email.name, start_date=obj.start_date, end_date=obj.end_date))
obj.delete()
print(messageKanaka)
print(messageGauri)
print(messageAjay)
if(messageAjay): caterer_mail(messageAjay, "Ajay","[email protected]", date)
if(messageKanaka): caterer_mail(messageKanaka, "Kanaka","[email protected]",date)
if(messageGauri): caterer_mail(messageGauri, "Gauri","[email protected]",date)
for caterer in Caterer.objects.all():
print(caterer.name)
message_caterer = ""
date = today
for obj in queryset:
print(obj.Caterer)
if(obj.Caterer != caterer.name): continue
allocation=obj.allocation_id
message_caterer +=(text.format(allocation_id=allocation.student_id,name=allocation.email.name, start_date=obj.start_date, end_date=obj.end_date))
obj.delete()
print(message_caterer)
if(message_caterer): caterer_mail(message_caterer, caterer.name,caterer.email, date)


rebate_fields={"fields": (
Expand Down
2 changes: 2 additions & 0 deletions home/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ class HomeConfig(AppConfig):

def ready(self):
import home.signals
from .schedulers import start
start()

3 changes: 2 additions & 1 deletion home/models/caterer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Caterer(models.Model):
student_limit = models.IntegerField(
_("Caterers Student Limit"), default=0, help_text="The limit on number of students it can have")
visible = models.BooleanField(_("Visible"), default=False,null=True, help_text="If the caterer is visible or not to the students")

email = models.EmailField(_("Caterer Email"), max_length=254,
help_text="The email of the caterer", default="")
def __str__(self):
return "Caterer " + self.name

Expand Down
10 changes: 10 additions & 0 deletions home/schedulers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django_apscheduler.jobstores import DjangoJobStore, register_events
from apscheduler.schedulers.background import BackgroundScheduler
from .utils.django_email_server import __send__rebate__email__

def start():
scheduler = BackgroundScheduler()
scheduler.add_jobstore(DjangoJobStore(), "default")
scheduler.add_job(__send__rebate__email__, 'cron', hour=23, minute=59, second=0)
register_events(scheduler)
scheduler.start()
23 changes: 22 additions & 1 deletion home/utils/django_email_server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# django-email-server.py

from ..models.students import TodayRebate
from ..models.caterer import Caterer
from django.core.mail import send_mail
from django.core import mail
from django.conf import settings
Expand Down Expand Up @@ -73,3 +74,23 @@ def long_rebate_mail(start_date, end_date, approved, recipient, left_start_date,
else:
message = message_long_rebate.format(start_date=start_date, end_date=end_date, approved = "rejected",added="added to")
send(subject, message, recipient)

def __send__rebate__email__():
from datetime import date
today = date.today()
queryset = TodayRebate.objects.filter(date=today)
text = "<li> {name} with {allocation_id} has applied from {start_date} to {end_date}</li>"
for caterer in Caterer.objects.all():
message_caterer = ""
date = today
print(caterer.name)
print(queryset)
for obj in queryset:
if(obj.Caterer != caterer.name): continue
allocation=obj.allocation_id
message_caterer +=(text.format(allocation_id=allocation.student_id,name=allocation.email.name, start_date=obj.start_date, end_date=obj.end_date))
obj.delete()
print(message_caterer)
if(message_caterer): caterer_mail(message_caterer, caterer.name,caterer.email, date)
return

2 changes: 2 additions & 0 deletions messWebsite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"django.contrib.admindocs",
'cloudinary_storage',
'cloudinary',
'apscheduler',
'django_apscheduler'
]

MIDDLEWARE = [
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ whitenoise==6.4.0
django-cloudinary-storage==0.3.0
django-admin-logs==1.0.2
Pillow
django-apscheduler
# django-cloudinary-storage==0.3.0

0 comments on commit 86db307

Please sign in to comment.