Skip to content

Commit

Permalink
Signal fix (#69)
Browse files Browse the repository at this point in the history
* fix: import signals.py in app.py

* nit fix

---------

Co-authored-by: Ishaan Mittal <[email protected]>
  • Loading branch information
mittal-ishaan and ishaan-tf authored Aug 17, 2024
1 parent 6050430 commit 02f4dfb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ per-file-ignores =
home/models/students.py: E402
home/models/admin.py: F811
home/models/__init__.py: F401
home/apps.py: F401
2 changes: 2 additions & 0 deletions home/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class HomeConfig(AppConfig):
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)
Expand Down
24 changes: 14 additions & 10 deletions home/signals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver

Expand All @@ -20,6 +22,8 @@
from .utils.rebate_checker import count

__doc__ = "This file contains the signals for the home app"
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


@receiver(post_save, sender=Student)
Expand Down Expand Up @@ -55,14 +59,14 @@ def direct_update_bill(sender, instance, created, **kwargs):
rebate_mail(
instance.start_date, instance.end_date, instance.approved, email.email
)
print("Saved")
logger.info("Saved")
except Exception as e:
print(e)
logger.error(e)


@receiver(pre_save, sender=Rebate)
def update_short_bill(sender, instance, **kwargs):
print("Signal called for Short Rebate")
logger.info("Signal called for Short Rebate")
try:
old_instance = Rebate.objects.get(pk=instance.pk)
if old_instance.approved != instance.approved:
Expand All @@ -71,7 +75,7 @@ def update_short_bill(sender, instance, **kwargs):
start_date = instance.start_date
end_date = instance.end_date
days = count(start_date, end_date)
print(old_instance.approved, instance.approved)
logger.info(old_instance.approved, instance.approved)
if instance.approved is True and days > 0:
save_short_bill(
email,
Expand All @@ -88,7 +92,7 @@ def update_short_bill(sender, instance, **kwargs):
end_date=end_date,
)
new_rebate.save()
print("Saved")
logger.info("Saved")
else:
save_short_bill(
email,
Expand All @@ -104,19 +108,19 @@ def update_short_bill(sender, instance, **kwargs):
.last()
.delete()
)
print("Deleted")
logger.info("Deleted")
rebate_mail(
instance.start_date, instance.end_date, instance.approved, email.email
)
except Exception as e:
print(e)
logger.error(e)


@receiver(pre_save, sender=LongRebate)
def update_long_bill(sender, instance, **kwargs):
try:
old_instance = LongRebate.objects.get(pk=instance.pk)
print(old_instance.approved, instance.approved)
logger.info(old_instance.approved, instance.approved)
if (
old_instance.approved != instance.approved
or old_instance.reason != instance.reason
Expand Down Expand Up @@ -159,7 +163,7 @@ def update_long_bill(sender, instance, **kwargs):
instance.reason,
)
except Exception as e:
print(e)
logger.error(e)


@receiver(post_save, sender=Allocation)
Expand Down Expand Up @@ -195,7 +199,7 @@ def update_rebate_bill(sender, instance, created, **kwargs):
rebate_bill.period6_bill = amount * days
rebate_bill.save()
except Exception as e:
print(e)
logger.error(e)


@receiver(post_save, sender=Period)
Expand Down
2 changes: 1 addition & 1 deletion home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def rebate(request):
except Allocation.DoesNotExist:
text = "Email ID does not match with the allocation ID"
except Exception as e:
print(e)
logger.error(e)
text = (
"Ohh No! an unknown ERROR occured, Please inform about it immediatly to the Dining Wadern. Possible Error: "
+ key
Expand Down

0 comments on commit 02f4dfb

Please sign in to comment.