Kumi
ae97cfa30e
Removed unnecessary imports across various modules to streamline the application's dependencies and improve loading times. Specific changes include the removal of unused Django model and admin imports in several apps, simplifying view imports by eliminating unutilized components, and cleaning up static CSS for better maintainability. Corrections were made to conditional expressions for clearer logic. The removal of the django.test.TestCase import in test files reflects a shift towards a different testing strategy or the current lack of tests. Exception handling has been made more explicit to avoid catching unintended exceptions, paving the way for more robust error handling and logging in the future. Additionally, a new CSS file was added for frontend enhancements, indicating ongoing UI/UX improvements. These changes collectively aim to make the codebase more maintainable and efficient, reducing clutter and focusing on used functionalities. It's a step towards optimizing the application's performance and ensuring a clean, manageable codebase for future development.
30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
from django.dispatch import receiver
|
|
from django.utils.timezone import localtime, now
|
|
|
|
from cronhandler.signals import cron
|
|
|
|
from .models import Notification
|
|
|
|
@receiver(cron)
|
|
def send_notifications(sender, **kwargs):
|
|
returns = []
|
|
for notification in Notification.objects.all():
|
|
for datetime in notification.notificationdatetimeschedule_set.all():
|
|
if not datetime.sent and datetime.datetime <= localtime(now()):
|
|
try:
|
|
returns.append(notification.send())
|
|
datetime.sent = True
|
|
datetime.save()
|
|
except Exception:
|
|
pass # TODO: Implement some sort of error logging / admin notification
|
|
for daily in notification.notificationdailyschedule_set.all():
|
|
if ((not daily.last_sent) or daily.last_sent < localtime(now()).date()) and daily.time <= localtime(now()).time():
|
|
try:
|
|
returns.append(notification.send())
|
|
daily.last_sent = localtime(now()).date()
|
|
daily.save()
|
|
except Exception:
|
|
pass # TODO: See above
|
|
|
|
return returns
|
|
|