Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signal fix #69

Merged
merged 2 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading