From 2c9f972a51d2c72384a01df54ed68e8974d4d675 Mon Sep 17 00:00:00 2001 From: Ishaan Mittal Date: Sun, 17 Nov 2024 13:09:20 +0530 Subject: [PATCH] delte apps schedular and todays rebate table --- api/utils/rebate_checker.py | 12 ++--- home/admin.py | 57 +--------------------- home/apps.py | 11 ----- home/migrations/0002_delete_todayrebate.py | 16 ++++++ home/models/__init__.py | 1 - home/models/students.py | 21 -------- home/schedulers.py | 14 ------ home/signals.py | 24 --------- home/utils/django_email_server.py | 31 ------------ messWebsite/settings.py | 33 +++++-------- requirements.txt | 2 - 11 files changed, 34 insertions(+), 188 deletions(-) create mode 100644 home/migrations/0002_delete_todayrebate.py delete mode 100644 home/schedulers.py diff --git a/api/utils/rebate_checker.py b/api/utils/rebate_checker.py index b2d211d..c3ab4bd 100644 --- a/api/utils/rebate_checker.py +++ b/api/utils/rebate_checker.py @@ -1,5 +1,6 @@ from django.utils import timezone -from home.models.students import Student, LongRebate, Rebate, Allocation + +from home.models.students import Allocation, LongRebate, Rebate, Student def is_student_on_rebate(student: Student, allocation: Allocation): @@ -8,19 +9,16 @@ def is_student_on_rebate(student: Student, allocation: Allocation): """ today = timezone.localtime().date() - # Check if there is a TodayRebate for the given allocation + # Check if there is a ShortRebate for the given allocation if Rebate.objects.filter( allocation_id=allocation, start_date__lte=today, end_date__gte=today, - approved=True + approved=True, ).exists(): return True # Check if there is an approved LongRebate for the student within the date range return LongRebate.objects.filter( - email=student, - start_date__lte=today, - end_date__gte=today, - approved=True + email=student, start_date__lte=today, end_date__gte=today, approved=True ).exists() diff --git a/home/admin.py b/home/admin.py index c87dcb5..515b7ac 100644 --- a/home/admin.py +++ b/home/admin.py @@ -33,7 +33,6 @@ Semester, Student, StudentBills, - TodayRebate, UnregisteredStudent, Update, ) @@ -48,7 +47,7 @@ StudentResource, UnregisteredStudentResource, ) -from .utils.django_email_server import caterer_mail, long_rebate_query_mail +from .utils.django_email_server import long_rebate_query_mail from .utils.month import fill_periods, map_periods_to_long_rebate from .utils.rebate_bills_saver import ( fix_all_bills, @@ -642,52 +641,6 @@ def check_student(self, request, queryset): continue -@admin.register(TodayRebate) -class about_Admin(ImportExportModelAdmin, admin.ModelAdmin): - model = TodayRebate - search_fields = ("Caterer", "allocation_id", "date") - list_display = ("allocation_id", "date", "start_date", "end_date") - # list_filter = () - fieldsets = ( - ( - None, - { - "fields": ( - "date", - "Caterer", - "allocation_id", - "start_date", - "end_date", - ) - }, - ), - ) - - actions = ["send_mail"] - - @admin.action(description="Send mail to the caterer") - def send_mail(self, request, queryset): - text = "
  • {name} with {allocation_id} has applied from {start_date} to {end_date}
  • " - for caterer in Caterer.objects.all(): - print(caterer.name) - message_caterer = "" - 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, obj.date) - - rebate_fields = { "fields": ( "email", @@ -1244,14 +1197,6 @@ def Add(self, request, queryset): allocation.high_tea, allocation.caterer, ) - new_rebate = TodayRebate( - date=obj.date_applied, - Caterer=allocation.caterer, - allocation_id=allocation, - start_date=obj.start_date, - end_date=obj.end_date, - ) - new_rebate.save() print("Saved") short_rebate = Rebate( email=student_obj, diff --git a/home/apps.py b/home/apps.py index aeae5ec..00db6ea 100644 --- a/home/apps.py +++ b/home/apps.py @@ -15,14 +15,3 @@ def ready(self): import socket import home.signals - - # bind to port 47200, then check for it for every worker - try: - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.bind(("127.0.0.1", 47200)) - except socket.error: - print, "!!!scheduler already started, DO NOTHING" - else: - from .schedulers import start - - start() diff --git a/home/migrations/0002_delete_todayrebate.py b/home/migrations/0002_delete_todayrebate.py new file mode 100644 index 0000000..8665658 --- /dev/null +++ b/home/migrations/0002_delete_todayrebate.py @@ -0,0 +1,16 @@ +# Generated by Django 5.0.8 on 2024-11-17 07:35 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0001_initial'), + ] + + operations = [ + migrations.DeleteModel( + name='TodayRebate', + ), + ] diff --git a/home/models/__init__.py b/home/models/__init__.py index 1ac6463..b917faa 100644 --- a/home/models/__init__.py +++ b/home/models/__init__.py @@ -23,7 +23,6 @@ Rebate, Scan, Student, - TodayRebate, UnregisteredStudent, ) from .allocation import Allocation, Period, Semester diff --git a/home/models/students.py b/home/models/students.py index 67ffaec..1db5527 100644 --- a/home/models/students.py +++ b/home/models/students.py @@ -203,27 +203,6 @@ class Meta: verbose_name_plural = "Unregistered Students" -class TodayRebate(models.Model): - date = models.DateField(help_text="Date of the rebate", default=now) - Caterer = models.CharField(max_length=30, default="") - allocation_id = models.ForeignKey( - Allocation, on_delete=models.SET_NULL, null=True, blank=True - ) - start_date = models.DateField( - help_text="start date of the rebate", null=True, blank=True - ) - end_date = models.DateField( - help_text="end date of the rebate", null=True, blank=True - ) - - def __str__(self): - return str(self.date) + " " + str(self.allocation_id) - - class Meta: - verbose_name = "Today's Rebate" - verbose_name_plural = "Today's Rebate" - - class LeftLongRebate(models.Model): email = models.CharField(_("email"), max_length=30, default="") start_date = models.DateField( diff --git a/home/schedulers.py b/home/schedulers.py deleted file mode 100644 index feb23bc..0000000 --- a/home/schedulers.py +++ /dev/null @@ -1,14 +0,0 @@ -from apscheduler.schedulers.background import BackgroundScheduler -from django_apscheduler.jobstores import DjangoJobStore, register_events - -from .utils.django_email_server import __send__rebate__email__ - - -def start(): - scheduler = BackgroundScheduler() - if scheduler is None: - scheduler.add_jobstore(DjangoJobStore(), "default") - scheduler.add_job(__send__rebate__email__, "cron", hour=23, minute=59, second=0) - register_events(scheduler) - scheduler.start() - print(scheduler) diff --git a/home/signals.py b/home/signals.py index bf5c891..b4523e6 100644 --- a/home/signals.py +++ b/home/signals.py @@ -14,7 +14,6 @@ Semester, Student, StudentBills, - TodayRebate, UnregisteredStudent, ) from .utils.django_email_server import long_rebate_mail, rebate_mail @@ -49,14 +48,6 @@ def direct_update_bill(sender, instance, created, **kwargs): save_short_bill( email, allocation.period, days, allocation.high_tea, allocation.caterer ) - new_rebate = TodayRebate( - date=instance.date_applied, - Caterer=allocation.caterer.name, - allocation_id=allocation, - start_date=start_date, - end_date=end_date, - ) - new_rebate.save() rebate_mail( instance.start_date, instance.end_date, instance.approved, email.email ) @@ -85,14 +76,6 @@ def update_short_bill(sender, instance, **kwargs): allocation.high_tea, allocation.caterer, ) - new_rebate = TodayRebate( - date=instance.date_applied, - Caterer=allocation.caterer.name, - allocation_id=allocation, - start_date=start_date, - end_date=end_date, - ) - new_rebate.save() logger.info("Saved") else: save_short_bill( @@ -102,13 +85,6 @@ def update_short_bill(sender, instance, **kwargs): allocation.high_tea, allocation.caterer, ) - new_rebate = ( - TodayRebate.objects.filter( - allocation_id=allocation, start_date=start_date - ) - .last() - .delete() - ) logger.info("Deleted") rebate_mail( instance.start_date, instance.end_date, instance.approved, email.email diff --git a/home/utils/django_email_server.py b/home/utils/django_email_server.py index ffccbf7..99ae1a9 100644 --- a/home/utils/django_email_server.py +++ b/home/utils/django_email_server.py @@ -3,9 +3,6 @@ from django.core import mail from django.core.mail import send_mail -from ..models.caterer import Caterer -from ..models.students import TodayRebate - def send(subject, message, recipient): with mail.get_connection() as connection: @@ -119,31 +116,3 @@ 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() - queryset = TodayRebate.objects.filter(date=today) - text = "
  • {name} with {allocation_id} has applied from {start_date} to {end_date}
  • " - 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 diff --git a/messWebsite/settings.py b/messWebsite/settings.py index 31b80a3..edfd41e 100644 --- a/messWebsite/settings.py +++ b/messWebsite/settings.py @@ -43,16 +43,13 @@ "allauth.socialaccount.providers.google", "cloudinary_storage", "cloudinary", - "apscheduler", - "django_apscheduler", - 'rest_framework', - 'rest_framework.authtoken', - 'drf_yasg', - + "rest_framework", + "rest_framework.authtoken", + "drf_yasg", # Local apps "home.apps.HomeConfig", "qrscan.apps.QrscanConfig", - 'api', + "api", ] MIDDLEWARE = [ @@ -169,25 +166,19 @@ ) REST_FRAMEWORK = { - 'DEFAULT_AUTHENTICATION_CLASSES': [ - 'rest_framework.authentication.TokenAuthentication', + "DEFAULT_AUTHENTICATION_CLASSES": [ + "rest_framework.authentication.TokenAuthentication", ], - 'DEFAULT_PERMISSION_CLASSES': [ - 'rest_framework.permissions.IsAuthenticated', + "DEFAULT_PERMISSION_CLASSES": [ + "rest_framework.permissions.IsAuthenticated", ], } SWAGGER_SETTINGS = { - 'SECURITY_DEFINITIONS': { - 'Basic': { - 'type': 'basic' - }, - 'Token': { - 'type': 'apiKey', - 'name': 'Authorization', - 'in': 'header' - } - } + "SECURITY_DEFINITIONS": { + "Basic": {"type": "basic"}, + "Token": {"type": "apiKey", "name": "Authorization", "in": "header"}, + } } ACCOUNT_ADAPTER = "home.adapters.account_adapter.CustomAccountAdapter" diff --git a/requirements.txt b/requirements.txt index ae2c0a2..c930ddd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,6 @@ -APScheduler==3.10.4 cloudinary==1.41.0 Django==5.0.9 django_allauth==0.54.0 -django_apscheduler==0.7.0 django_environ==0.10.0 django_import_export==3.2.0 djangorestframework==3.15.2