From 1433be38566ead7e2f0c98e5595d37483b632499 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Fri, 16 Nov 2012 10:07:19 -0500 Subject: [PATCH 1/8] customizing this on a per-user basis is going to be a pain, hence no amount --- .../notification/wishlist_near_deadline/full.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/templates/notification/wishlist_near_deadline/full.txt b/frontend/templates/notification/wishlist_near_deadline/full.txt index e344a1b1..029cdaf9 100644 --- a/frontend/templates/notification/wishlist_near_deadline/full.txt +++ b/frontend/templates/notification/wishlist_near_deadline/full.txt @@ -1,11 +1,11 @@ {% load humanize %}{% if campaign.left > 0 %} The campaign to unglue a book you've wishlisted, {{ campaign.work.title}}, is almost out of time. We need to raise ${{ campaign.left|intcomma }} more by {{ campaign.deadline }} in order to give this book to the world. {% if pledged %} - Your pledge of {{ amount|intcomma }} is helping {{ campaign.work.title }} to reach its goal, but we can only unglue this book if the campaign succeeds. You can help your pledge go farther by sharing the campaign (https://{{ site.domain }}{% url work work_id=campaign.work.id %}) with your friends through your favorite media: tweet, Facebook, Tumblr, blog, G+, Pinterest, email, carrier pigeon, or good old-fashioned conversation. + Your pledge is helping {{ campaign.work.title }} to reach its goal, but we can only unglue this book if the campaign succeeds. You can help your pledge go farther by sharing the campaign (https://{{ domain }}{% url work work_id=campaign.work.id %}) with your friends through your favorite media: tweet, Facebook, Tumblr, blog, G+, Pinterest, email, carrier pigeon, or good old-fashioned conversation. {% else %} - We need your pledge to reach this target. Any amount helps. You can chip in towards giving this book to the world at https://{{ site.domain }}{% url pledge work_id=campaign.work.id %} . + If you've been meaning to get around to pledging, now's your chance. Any amount helps. You can chip in towards giving this book to the world at https://{{ domain }}{% url pledge work_id=campaign.work.id %} . - You can also help by sharing the campaign (https://{{ site.domain }}{% url work work_id=campaign.work.id %}) with your friends through your favorite media: tweet, Facebook, Tumblr, blog, G+, Pinterest, email, carrier pigeon, or good old-fashioned conversation. + You can also help by sharing the campaign (https://{{ domain }}{% url work work_id=campaign.work.id %}) with your friends through your favorite media: tweet, Facebook, Tumblr, blog, G+, Pinterest, email, carrier pigeon, or good old-fashioned conversation. {% endif %} Thank you! @@ -14,9 +14,9 @@ The campaign to unglue a book you've wishlisted, {{ campaign.work.title}}, is on track to succeed! It has met its target price of {{ campaign.target|intcomma }} and will close soon. {% if pledged %} - Your pledge of ${{ amount|intcomma }} is helping us give this book to the world. Thank you! When the campaign closes, we'll be in touch about how and when you'll receive your premiums. + Your pledge is helping us give this book to the world. Thank you! When the campaign closes, we'll be in touch about how and when you'll receive your premiums. {% else %} - If you wanted to support this campaign, this is your last chance. Pledge by midnight (Eastern US time) if you want to help the campaign or receive any premiums: https://{{ site.domain }}{% url pledge work_id=campaign.work.id %} + If you wanted to support this campaign, this is your last chance. Pledge by midnight (Eastern US time) if you want to help the campaign or receive any premiums: https://{{ domain }}{% url pledge work_id=campaign.work.id %} {% endif %} Thanks to ungluers like you, we'll soon be able to give this book to the world together. Hooray! From 87da5ae50e055ee4a1d49d379c6e66ae46fc5745 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Fri, 16 Nov 2012 10:07:45 -0500 Subject: [PATCH 2/8] tweaking phrasing following user feedback --- .../notification/wishlist_near_deadline/notice.html | 5 +++-- .../templates/notification/wishlist_near_deadline/short.txt | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/templates/notification/wishlist_near_deadline/notice.html b/frontend/templates/notification/wishlist_near_deadline/notice.html index 33468afa..2ce83eb4 100644 --- a/frontend/templates/notification/wishlist_near_deadline/notice.html +++ b/frontend/templates/notification/wishlist_near_deadline/notice.html @@ -5,7 +5,7 @@ {% endblock %} {% block comments_graphical %} - The campaign for {{ campaign.work.title }} is almost over. + The campaign to unglue {{ campaign.work.title }} is almost over. {% endblock %} {% block comments_textual %} @@ -13,8 +13,9 @@ {% if pledged %} Your pledge is helping us reach that goal. Will you help again by sharing this campaign with your friends? + {% else %} - You can help us give this book to the world by pledging or by sharing this campaign with your friends. + If you've been meaning to pledge, now's your chance. You can also help by sharing this campaign with your friends. {% endif %} {% url work campaign.work.id as work_url %} diff --git a/frontend/templates/notification/wishlist_near_deadline/short.txt b/frontend/templates/notification/wishlist_near_deadline/short.txt index 48bec954..a8a7cb73 100644 --- a/frontend/templates/notification/wishlist_near_deadline/short.txt +++ b/frontend/templates/notification/wishlist_near_deadline/short.txt @@ -1 +1 @@ -{{campaign.work.title}} is running out of time \ No newline at end of file +Almost out of time to unglue {{campaign.work.title}} \ No newline at end of file From f25f3c81ee5eedadcfb31a92517f0f1c253eaeb7 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Fri, 16 Nov 2012 10:24:48 -0500 Subject: [PATCH 3/8] construct notification handler --- core/signals.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/core/signals.py b/core/signals.py index afebdbc1..70e29d57 100644 --- a/core/signals.py +++ b/core/signals.py @@ -238,3 +238,30 @@ def handle_wishlist_added(supporter, work, **kwargs): emit_notifications.delay() wishlist_added.connect(handle_wishlist_added) + +deadline_impending = Signal(providing_args["campaign"]) + +def handle_wishlist_near_deadline(campaign, **kwargs): + """ + send two groups - one the nonpledgers, one the pledgers + set the pledged flag differently in the context + """ + pledgers = campaign.supporters() + nonpledgers = campaign.work.wished_by().exclude(id__in=pledgers) + + notification.queue(pledgers, "wishlist_near_deadline", { + 'campaign': campaign, + 'domain': settings.BASE_URL, + 'pledged': True, + }, True) + + notification.queue(nonpledgers, "wishlist_near_deadline", { + 'campaign': campaign, + 'domain': settings.BASE_URL, + 'pledged': False, + }, True) + + from regluit.core.tasks import emit_notifications + emit_notifications.delay() + +deadline_impending.connect(handle_wishlist_near_deadline) \ No newline at end of file From 4719c0b4b4a74f9313a3a3f84c4ce867973dd0c4 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Fri, 16 Nov 2012 10:37:12 -0500 Subject: [PATCH 4/8] fire signal for time-running-out notification --- core/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/models.py b/core/models.py index e5b6f64f..0f318d8f 100755 --- a/core/models.py +++ b/core/models.py @@ -16,7 +16,7 @@ from django.utils.translation import ugettext_lazy as _ import regluit import regluit.core.isbn -from regluit.core.signals import successful_campaign, unsuccessful_campaign, wishlist_added +from regluit.core.signals import successful_campaign, unsuccessful_campaign, wishlist_added, deadline_impending import binascii from regluit.payment.parameters import TRANSACTION_STATUS_ACTIVE, TRANSACTION_STATUS_COMPLETE, TRANSACTION_STATUS_CANCELED, TRANSACTION_STATUS_ERROR, TRANSACTION_STATUS_FAILED, TRANSACTION_STATUS_INCOMPLETE @@ -320,6 +320,11 @@ class Campaign(models.Model): results = p.cancel_campaign(self) # should be more sophisticated in whether to return True -- look at all the transactions return True + elif self.deadline - now() < timedelta(7) and self.deadline - now() > timedelta(6): + """ + if the campaign is still active and there's only a week left until it closes, send reminder notification + """ + deadline_impending.send(sender=self, campaign=self) else: return False From 2858ed194c59ddaecfeeb51dd3079719d1c2834c Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Fri, 16 Nov 2012 11:43:00 -0500 Subject: [PATCH 5/8] bugfixing --- core/signals.py | 8 ++++---- .../notification/wishlist_near_deadline/full.txt | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/signals.py b/core/signals.py index 70e29d57..fad3982c 100644 --- a/core/signals.py +++ b/core/signals.py @@ -239,22 +239,22 @@ def handle_wishlist_added(supporter, work, **kwargs): wishlist_added.connect(handle_wishlist_added) -deadline_impending = Signal(providing_args["campaign"]) +deadline_impending = Signal(providing_args=["campaign"]) def handle_wishlist_near_deadline(campaign, **kwargs): """ send two groups - one the nonpledgers, one the pledgers set the pledged flag differently in the context """ - pledgers = campaign.supporters() - nonpledgers = campaign.work.wished_by().exclude(id__in=pledgers) + pledgers = campaign.ungluers()['all'] + nonpledgers = campaign.work.wished_by().exclude(id__in=[p.id for p in pledgers]) notification.queue(pledgers, "wishlist_near_deadline", { 'campaign': campaign, 'domain': settings.BASE_URL, 'pledged': True, }, True) - + notification.queue(nonpledgers, "wishlist_near_deadline", { 'campaign': campaign, 'domain': settings.BASE_URL, diff --git a/frontend/templates/notification/wishlist_near_deadline/full.txt b/frontend/templates/notification/wishlist_near_deadline/full.txt index 029cdaf9..e6963c33 100644 --- a/frontend/templates/notification/wishlist_near_deadline/full.txt +++ b/frontend/templates/notification/wishlist_near_deadline/full.txt @@ -1,11 +1,11 @@ {% load humanize %}{% if campaign.left > 0 %} The campaign to unglue a book you've wishlisted, {{ campaign.work.title}}, is almost out of time. We need to raise ${{ campaign.left|intcomma }} more by {{ campaign.deadline }} in order to give this book to the world. {% if pledged %} - Your pledge is helping {{ campaign.work.title }} to reach its goal, but we can only unglue this book if the campaign succeeds. You can help your pledge go farther by sharing the campaign (https://{{ domain }}{% url work work_id=campaign.work.id %}) with your friends through your favorite media: tweet, Facebook, Tumblr, blog, G+, Pinterest, email, carrier pigeon, or good old-fashioned conversation. + Your pledge is helping {{ campaign.work.title }} to reach its goal, but we can only unglue this book if the campaign succeeds. You can help your pledge go farther by sharing the campaign ({{ domain }}{% url work work_id=campaign.work.id %}) with your friends through your favorite media: tweet, Facebook, Tumblr, blog, G+, Pinterest, email, carrier pigeon, or good old-fashioned conversation. {% else %} - If you've been meaning to get around to pledging, now's your chance. Any amount helps. You can chip in towards giving this book to the world at https://{{ domain }}{% url pledge work_id=campaign.work.id %} . + If you've been meaning to get around to pledging, now's your chance. Any amount helps. You can chip in towards giving this book to the world at {{ domain }}{% url pledge work_id=campaign.work.id %} . - You can also help by sharing the campaign (https://{{ domain }}{% url work work_id=campaign.work.id %}) with your friends through your favorite media: tweet, Facebook, Tumblr, blog, G+, Pinterest, email, carrier pigeon, or good old-fashioned conversation. + You can also help by sharing the campaign ({{ domain }}{% url work work_id=campaign.work.id %}) with your friends through your favorite media: tweet, Facebook, Tumblr, blog, G+, Pinterest, email, carrier pigeon, or good old-fashioned conversation. {% endif %} Thank you! @@ -16,7 +16,7 @@ {% if pledged %} Your pledge is helping us give this book to the world. Thank you! When the campaign closes, we'll be in touch about how and when you'll receive your premiums. {% else %} - If you wanted to support this campaign, this is your last chance. Pledge by midnight (Eastern US time) if you want to help the campaign or receive any premiums: https://{{ domain }}{% url pledge work_id=campaign.work.id %} + If you wanted to support this campaign, this is your last chance. Pledge by midnight (Eastern US time) if you want to help the campaign or receive any premiums: {{ domain }}{% url pledge work_id=campaign.work.id %} {% endif %} Thanks to ungluers like you, we'll soon be able to give this book to the world together. Hooray! From 68a08d78c21e549f179f81adcfea1387e978c235 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Wed, 21 Nov 2012 09:12:21 -0500 Subject: [PATCH 6/8] Revert "fire signal for time-running-out notification" This reverts commit 4719c0b4b4a74f9313a3a3f84c4ce867973dd0c4. --- core/models.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/core/models.py b/core/models.py index 0f318d8f..e5b6f64f 100755 --- a/core/models.py +++ b/core/models.py @@ -16,7 +16,7 @@ from django.utils.translation import ugettext_lazy as _ import regluit import regluit.core.isbn -from regluit.core.signals import successful_campaign, unsuccessful_campaign, wishlist_added, deadline_impending +from regluit.core.signals import successful_campaign, unsuccessful_campaign, wishlist_added import binascii from regluit.payment.parameters import TRANSACTION_STATUS_ACTIVE, TRANSACTION_STATUS_COMPLETE, TRANSACTION_STATUS_CANCELED, TRANSACTION_STATUS_ERROR, TRANSACTION_STATUS_FAILED, TRANSACTION_STATUS_INCOMPLETE @@ -320,11 +320,6 @@ class Campaign(models.Model): results = p.cancel_campaign(self) # should be more sophisticated in whether to return True -- look at all the transactions return True - elif self.deadline - now() < timedelta(7) and self.deadline - now() > timedelta(6): - """ - if the campaign is still active and there's only a week left until it closes, send reminder notification - """ - deadline_impending.send(sender=self, campaign=self) else: return False From c4f32b38b543c5e48e88dea41180ce0355b45b77 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Wed, 21 Nov 2012 11:09:07 -0500 Subject: [PATCH 7/8] moving ending soon notification to tasks --- core/tasks.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/tasks.py b/core/tasks.py index fcdb8d25..38f8ed5a 100644 --- a/core/tasks.py +++ b/core/tasks.py @@ -12,6 +12,7 @@ from django.conf import settings from regluit.core import bookloader, models from regluit.core import goodreads, librarything from regluit.core.models import Campaign +from regluit.core.signals import deadline_impending from regluit.utils.localdatetime import now, date_today from django.core.mail import send_mail @@ -97,5 +98,16 @@ def report_new_ebooks(created=None): #created= creation date works = models.Work.objects.filter(editions__ebooks__created__range = period).distinct() for work in works: notification.send_now(work.wished_by(), "wishlist_unglued_book_released", {'work':work}, True) + +@task +def notify_ending_soon(): + c_active = Campaign.objects.filter(status='Active') + for c in c_active: + if c.deadline - now() < timedelta(7) and c.deadline - now() >= timedelta(6): + """ + if the campaign is still active and there's only a week left until it closes, send reminder notification + """ + deadline_impending.send(sender=None, campaign=c) + \ No newline at end of file From 84e13a42bf5f9d37ca605621528b58db010f6af8 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Wed, 21 Nov 2012 11:09:18 -0500 Subject: [PATCH 8/8] scheduling ending soon notification --- settings/common.py | 6 ++++++ settings/prod.py | 1 + 2 files changed, 7 insertions(+) diff --git a/settings/common.py b/settings/common.py index aa3ac0e1..6479f412 100644 --- a/settings/common.py +++ b/settings/common.py @@ -275,6 +275,12 @@ EBOOK_NOTIFICATIONS_JOB = { "args": () } +NOTIFY_ENDING_SOON_JOB = { + "task": "regluit.core.tasks.notify_ending_soon", + "schedule": crontab(hour=1, minute=0), + "args": () +} + # by default, in common, we don't turn any of the celerybeat jobs on -- turn them on in the local settings file # amazon or paypal for now. diff --git a/settings/prod.py b/settings/prod.py index fac9c264..ca7629db 100644 --- a/settings/prod.py +++ b/settings/prod.py @@ -138,6 +138,7 @@ CKEDITOR_UPLOAD_PATH = '/var/www/static/media/' # update the statuses of campaigns CELERYBEAT_SCHEDULE['update_active_campaign_statuses'] = UPDATE_ACTIVE_CAMPAIGN_STATUSES CELERYBEAT_SCHEDULE['report_new_ebooks'] = EBOOK_NOTIFICATIONS_JOB +CELERYBEAT_SCHEDULE['notify_ending_soon'] = NOTIFY_ENDING_SOON_JOB # set -- sandbox or production Amazon FPS? #AMAZON_FPS_HOST = "fps.sandbox.amazonaws.com"