Skip to content

Commit

Permalink
delte apps schedular and todays rebate table
Browse files Browse the repository at this point in the history
  • Loading branch information
mittal-ishaan committed Nov 17, 2024
1 parent 43682ea commit 2c9f972
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 188 deletions.
12 changes: 5 additions & 7 deletions api/utils/rebate_checker.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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()
57 changes: 1 addition & 56 deletions home/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
Semester,
Student,
StudentBills,
TodayRebate,
UnregisteredStudent,
Update,
)
Expand All @@ -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,
Expand Down Expand Up @@ -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 = "<li> {name} with {allocation_id} has applied from {start_date} to {end_date}</li>"
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",
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 0 additions & 11 deletions home/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
16 changes: 16 additions & 0 deletions home/migrations/0002_delete_todayrebate.py
Original file line number Diff line number Diff line change
@@ -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',
),
]
1 change: 0 additions & 1 deletion home/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
Rebate,
Scan,
Student,
TodayRebate,
UnregisteredStudent,
)
from .allocation import Allocation, Period, Semester
Expand Down
21 changes: 0 additions & 21 deletions home/models/students.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 0 additions & 14 deletions home/schedulers.py

This file was deleted.

24 changes: 0 additions & 24 deletions home/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
Semester,
Student,
StudentBills,
TodayRebate,
UnregisteredStudent,
)
from .utils.django_email_server import long_rebate_mail, rebate_mail
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down
31 changes: 0 additions & 31 deletions home/utils/django_email_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 = "<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
33 changes: 12 additions & 21 deletions messWebsite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2c9f972

Please sign in to comment.