From fc2e876ce0758d85846631e9667a4f08fc633d38 Mon Sep 17 00:00:00 2001 From: lance Date: Thu, 23 Jan 2020 15:30:45 -0800 Subject: [PATCH] add new notif task to tell sellers about item statuses every few days and add num of bids in listing --- items/tasks/__init__.py | 2 +- items/tasks/notifications.py | 21 +++++++++++++++++++ web/templates/items/list_items.html | 2 ++ .../notify/item_has_bids/seller/body.txt | 9 ++++++++ .../notify/item_has_bids/seller/subject.txt | 1 + 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 items/tasks/notifications.py create mode 100644 web/templates/items/notify/item_has_bids/seller/body.txt create mode 100644 web/templates/items/notify/item_has_bids/seller/subject.txt 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 @@ List Date Whereabouts Asking Price (XMR) + Bids {% for item in items %} @@ -48,6 +49,7 @@ {{ item.list_date | date:"d M, Y H:i:s" }} {{ item.whereabouts }} {{ item.ask_price_xmr }} + {{ item.bids.all | length }} {% endfor %} diff --git a/web/templates/items/notify/item_has_bids/seller/body.txt b/web/templates/items/notify/item_has_bids/seller/body.txt new file mode 100644 index 0000000..ce5bbf7 --- /dev/null +++ b/web/templates/items/notify/item_has_bids/seller/body.txt @@ -0,0 +1,9 @@ +Congratulations {{ item.owner }}, + +Your item, "{{ item.name }}" (#{{ item.id }}), has received {{ item.bids.values | length }} bid(s). + +Please review the bids whenever you can. A link to the item is below: + +https://{{ site_url }}{{ item_path }} + +Thanks for using {{ site_name }}! diff --git a/web/templates/items/notify/item_has_bids/seller/subject.txt b/web/templates/items/notify/item_has_bids/seller/subject.txt new file mode 100644 index 0000000..d686ac2 --- /dev/null +++ b/web/templates/items/notify/item_has_bids/seller/subject.txt @@ -0,0 +1 @@ +[{{ site_name }}] Bids Received! (#{{ item.id }})