diff --git a/items/tasks/__init__.py b/items/tasks/__init__.py index cb71453..00993db 100644 --- a/items/tasks/__init__.py +++ b/items/tasks/__init__.py @@ -1 +1 @@ -from items.tasks import cleanup \ No newline at end of file +from items.tasks import cleanup, notifications \ No newline at end of file diff --git a/items/tasks/notifications.py b/items/tasks/notifications.py new file mode 100644 index 0000000..7aa7d83 --- /dev/null +++ b/items/tasks/notifications.py @@ -0,0 +1,21 @@ +from logging import getLogger +from huey import crontab +from huey.contrib.djhuey import periodic_task +from core.helpers.email_template import EmailTemplate +from items.models import Item + + +logger = getLogger('django.server') + +@periodic_task(crontab(minute='0', hours='0', days='*/2')) +def notify_seller_of_item_bids(): + items = Item.objects.all() + for item in items: + if len(item.bids.all()) > 0: + logger.info(f'[INFO] Item #{item.id} has some bids. Notifying the seller.') + email_template = EmailTemplate( + item=item, + scenario='item_has_bids', + role='seller' + ) + email_template.send() \ No newline at end of file diff --git a/web/templates/items/list_items.html b/web/templates/items/list_items.html index 7424f70..bf4f332 100644 --- a/web/templates/items/list_items.html +++ b/web/templates/items/list_items.html @@ -33,6 +33,7 @@