From a4e9855b35447f78af7c21e69b47f041e916c602 Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 8 Apr 2016 18:45:50 -0400 Subject: [PATCH] revert to older, patched Notification --- admin.py | 2 ++ core/models.py | 2 +- core/signals.py | 25 ++++++++++++++++++++++++- core/tasks.py | 11 ++++++++--- frontend/tests.py | 1 + frontend/views.py | 2 +- notebooks/PR447_Improve_Gifts.ipynb | 12 ++++++------ notebooks/expiring_stripe_cc.ipynb | 4 ++-- notebooks/expiring_stripe_cc.py | 5 +++-- payment/models.py | 4 ++-- payment/signals.py | 2 ++ payment/tasks.py | 4 ++++ requirements_versioned.pip | 3 ++- 13 files changed, 58 insertions(+), 19 deletions(-) diff --git a/admin.py b/admin.py index cb7c7b18..00265205 100644 --- a/admin.py +++ b/admin.py @@ -26,6 +26,7 @@ from notification.models import ( NoticeSetting, Notice, ObservedItem, + NoticeQueueBatch ) from selectable.forms import AutoCompleteSelectWidget,AutoCompleteSelectField @@ -292,6 +293,7 @@ admin_site.register(PeriodicTask, PeriodicTaskAdmin) # add the django-notification admin panel # https://github.com/jtauber/django-notification/blob/master/notification/admin.py +admin_site.register(NoticeQueueBatch, NoticeQueueBatchAdmin) admin_site.register(NoticeType, NoticeTypeAdmin) admin_site.register(NoticeSetting, NoticeSettingAdmin) admin_site.register(Notice, NoticeAdmin) diff --git a/core/models.py b/core/models.py index 807dbaef..306c0001 100755 --- a/core/models.py +++ b/core/models.py @@ -666,7 +666,7 @@ class Campaign(models.Model): self.save() action = CampaignAction( campaign = self, type='activated', comment = self.get_type_display()) ungluers = self.work.wished_by() - notification.send(ungluers, "wishlist_active", {'campaign':self}, True) + notification.queue(ungluers, "wishlist_active", {'campaign':self}, True) return self diff --git a/core/signals.py b/core/signals.py index d579dc24..64735e0a 100644 --- a/core/signals.py +++ b/core/signals.py @@ -111,10 +111,12 @@ def notify_comment(comment, request, **kwargs): domain = Site.objects.get_current().domain if comment.content_object.last_campaign() and comment.user in comment.content_object.last_campaign().managers.all(): #official - notification.send(all_wishers, "wishlist_official_comment", {'comment':comment, 'domain':domain}, True) + notification.queue(all_wishers, "wishlist_official_comment", {'comment':comment, 'domain':domain}, True) else: notification.send(other_commenters, "comment_on_commented", {'comment':comment}, True, sender=comment.user) notification.send(other_wishers, "wishlist_comment", {'comment':comment}, True, sender=comment.user) + from regluit.core.tasks import emit_notifications + emit_notifications.delay() comment_was_posted.connect(notify_comment) @@ -131,6 +133,8 @@ def notify_successful_campaign(campaign, **kwargs): supporters = (User.objects.get(id=k) for k in campaign.supporters()) notification.send(itertools.chain(staff, supporters), "wishlist_successful", {'campaign':campaign}, True) + from regluit.core.tasks import emit_notifications + emit_notifications.delay() # successful_campaign -> send notices successful_campaign.connect(notify_successful_campaign) @@ -145,6 +149,8 @@ def notify_unsuccessful_campaign(campaign, **kwargs): supporters = (User.objects.get(id=k) for k in campaign.supporters()) notification.send(itertools.chain(staff, supporters), "wishlist_unsuccessful", {'campaign':campaign}, True) + from regluit.core.tasks import emit_notifications + emit_notifications.delay() # unsuccessful_campaign -> send notices unsuccessful_campaign.connect(notify_unsuccessful_campaign) @@ -195,6 +201,9 @@ def handle_transaction_charged(sender,transaction=None, **kwargs): from regluit.core.tasks import send_mail_task message = render_to_string("notification/purchase_complete/full.txt", context ) send_mail_task.delay('unglue.it transaction confirmation', message, 'notices@gluejar.com', [transaction.receipt]) + if transaction.user: + from regluit.core.tasks import emit_notifications + emit_notifications.delay() transaction_charged.connect(handle_transaction_charged) @@ -212,6 +221,8 @@ def handle_transaction_failed(sender,transaction=None, **kwargs): 'transaction':transaction, 'recharge_deadline': recharge_deadline }, True) + from regluit.core.tasks import emit_notifications + emit_notifications.delay() transaction_failed.connect(handle_transaction_failed) @@ -229,6 +240,8 @@ def handle_pledge_modified(sender, transaction=None, up_or_down=None, **kwargs): 'transaction': transaction, 'up_or_down': up_or_down }, True) + from regluit.core.tasks import emit_notifications + emit_notifications.delay() pledge_modified.connect(handle_pledge_modified) @@ -243,6 +256,8 @@ def handle_you_have_pledged(sender, transaction=None, **kwargs): notification.send([transaction.user], "pledge_you_have_pledged", { 'transaction': transaction }, True) + from regluit.core.tasks import emit_notifications + emit_notifications.delay() pledge_created.connect(handle_you_have_pledged) @@ -256,6 +271,8 @@ def handle_wishlist_unsuccessful_amazon(campaign, **kwargs): supporters = (User.objects.get(id=k) for k in campaign.supporters()) notification.send(itertools.chain(staff, supporters), "wishlist_unsuccessful_amazon", {'campaign':campaign}, True) + from regluit.core.tasks import emit_notifications + emit_notifications.delay() amazon_suspension.connect(handle_wishlist_unsuccessful_amazon) @@ -271,6 +288,8 @@ def handle_wishlist_added(supporter, work, **kwargs): 'base_url': settings.BASE_URL_SECURE, }, True) + from regluit.core.tasks import emit_notifications + emit_notifications.delay() wishlist_added.connect(handle_wishlist_added) @@ -296,6 +315,8 @@ def handle_wishlist_near_deadline(campaign, **kwargs): 'pledged': False, }, True) + from regluit.core.tasks import emit_notifications + emit_notifications.delay() deadline_impending.connect(handle_wishlist_near_deadline) @@ -306,6 +327,8 @@ def notify_supporter_message(sender, work, supporter, msg, **kwargs): logger.info('received supporter_message signal for {0}'.format(supporter)) notification.send( [supporter], "wishlist_message", {'work':work, 'msg':msg}, True, sender) + from regluit.core.tasks import emit_notifications + emit_notifications.delay() supporter_message.connect(notify_supporter_message) diff --git a/core/tasks.py b/core/tasks.py index cdb4a536..37e43449 100644 --- a/core/tasks.py +++ b/core/tasks.py @@ -13,6 +13,7 @@ django imports from django.conf import settings from django.contrib.auth.models import User from django.core.mail import send_mail +from notification.engine import send_all from notification import models as notification """ @@ -98,6 +99,10 @@ def update_active_campaign_status(): """update the status of all active campaigns -- presumed to be run at midnight Eastern time""" return [c.update_status(send_notice=True, ignore_deadline_for_success=True, process_transactions=True) for c in Campaign.objects.filter(status='Active') ] +@task +def emit_notifications(): + logger.info('notifications emitting' ) + return send_all() @task def report_new_ebooks(created=None): #created= creation date @@ -107,7 +112,7 @@ def report_new_ebooks(created=None): #created= creation date period = (date_today()-timedelta(days=1), date_today()) works = models.Work.objects.filter(editions__ebooks__created__range = period).distinct() for work in works: - notification.send(work.wished_by(), "wishlist_unglued_book_released", {'work':work}, True) + notification.send_now(work.wished_by(), "wishlist_unglued_book_released", {'work':work}, True) @task def notify_ending_soon(): @@ -197,5 +202,5 @@ def notify_unclaimed_gifts(): """ unclaimed_duration = (now() - gift.acq.created ).days if unclaimed_duration > 0 and unclaimed_duration % 7 == 0 : # first notice in 7 days - notification.send([gift.acq.user], "purchase_gift_waiting", {'gift':gift}, True) - notification.send([gift.giver], "purchase_notgot_gift", {'gift':gift}, True) + notification.send_now([gift.acq.user], "purchase_gift_waiting", {'gift':gift}, True) + notification.send_now([gift.giver], "purchase_notgot_gift", {'gift':gift}, True) diff --git a/frontend/tests.py b/frontend/tests.py index d4e6ef1f..53375b2e 100755 --- a/frontend/tests.py +++ b/frontend/tests.py @@ -453,6 +453,7 @@ class UnifiedCampaignTests(TestCase): # print out notices and eventually write tests here to check expected + #from notification.models import Notice #print [(n.id, n.notice_type.label, n.recipient, n.added) for n in Notice.objects.all()] #[(6L, u'pledge_charged', , datetime.datetime(2012, 11, 21, 18, 33, 15)), diff --git a/frontend/views.py b/frontend/views.py index c2b2f261..1aaa9c4a 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -77,7 +77,7 @@ from regluit.core.bookloader import merge_works, detach_edition from regluit.core.goodreads import GoodreadsClient from regluit.core.search import gluejar_search from regluit.core.signals import supporter_message -from regluit.core.tasks import send_mail_task, watermark_acq +from regluit.core.tasks import send_mail_task, emit_notifications, watermark_acq from regluit.core.parameters import * from regluit.core.facets import get_facet_object, get_order_by diff --git a/notebooks/PR447_Improve_Gifts.ipynb b/notebooks/PR447_Improve_Gifts.ipynb index b1ac57ab..e3b9706c 100644 --- a/notebooks/PR447_Improve_Gifts.ipynb +++ b/notebooks/PR447_Improve_Gifts.ipynb @@ -31,8 +31,8 @@ " \"\"\"\n", " unclaimed_duration = (now() - gift.acq.created ).days\n", " if unclaimed_duration > 0 and unclaimed_duration % 7 == 0 : # first notice in 7 days\n", - " notification.send([gift.acq.user], \"purchase_gift_waiting\", {'gift':gift}, True)\n", - " notification.send([gift.giver], \"purchase_notgot_gift\", {'gift':gift}, True)\n", + " notification.send_now([gift.acq.user], \"purchase_gift_waiting\", {'gift':gift}, True)\n", + " notification.send_now([gift.giver], \"purchase_notgot_gift\", {'gift':gift}, True)\n", "````" ] }, @@ -53,8 +53,8 @@ " unclaimed_duration = (now_ - gift.acq.created ).days\n", " if unclaimed_duration > 0 and unclaimed_duration % 7 == 0 : # first notice in 7 days\n", " print (\"send notice\", now_, gift.acq.created, now_-gift.acq.created, gift.acq.user, gift.giver )\n", - "# notification.send([gift.acq.user], \"purchase_gift_waiting\", {'gift':gift}, True)\n", - "# notification.send([gift.giver], \"purchase_notgot_gift\", {'gift':gift}, True)" + "# notification.send_now([gift.acq.user], \"purchase_gift_waiting\", {'gift':gift}, True)\n", + "# notification.send_now([gift.giver], \"purchase_notgot_gift\", {'gift':gift}, True)" ], "language": "python", "metadata": {}, @@ -104,8 +104,8 @@ "To where is the emails of senders / recipients attached?\n", "\n", "\n", - " notification.send([gift.acq.user], \"purchase_gift_waiting\", {'gift':gift}, True)\n", - " notification.send([gift.giver], \"purchase_notgot_gift\", {'gift':gift}, True)\n" + " notification.send_now([gift.acq.user], \"purchase_gift_waiting\", {'gift':gift}, True)\n", + " notification.send_now([gift.giver], \"purchase_notgot_gift\", {'gift':gift}, True)\n" ] }, { diff --git a/notebooks/expiring_stripe_cc.ipynb b/notebooks/expiring_stripe_cc.ipynb index 33253ed4..f81ee73b 100644 --- a/notebooks/expiring_stripe_cc.ipynb +++ b/notebooks/expiring_stripe_cc.ipynb @@ -360,7 +360,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "notification.send([me], \"account_expiring\", {\n", + "notification.send_now([me], \"account_expiring\", {\n", " 'user': me, \n", " 'site':Site.objects.get_current()\n", " }, True)" @@ -374,7 +374,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "notification.send([me], \"account_expired\", {\n", + "notification.send_now([me], \"account_expired\", {\n", " 'user': me, \n", " 'site':Site.objects.get_current()\n", " }, True)" diff --git a/notebooks/expiring_stripe_cc.py b/notebooks/expiring_stripe_cc.py index 1a750e91..b3b48da1 100644 --- a/notebooks/expiring_stripe_cc.py +++ b/notebooks/expiring_stripe_cc.py @@ -144,6 +144,7 @@ Account.objects.filter(status='EXPIRED') # +from notification.engine import send_all from notification import models as notification from django.contrib.sites.models import Site @@ -160,14 +161,14 @@ print me, settings.EMAIL_HOST # -notification.send([me], "account_expiring", { +notification.send_now([me], "account_expiring", { 'user': me, 'site':Site.objects.get_current() }, True) # -notification.send([me], "account_expired", { +notification.send_now([me], "account_expired", { 'user': me, 'site':Site.objects.get_current() }, True) diff --git a/payment/models.py b/payment/models.py index 6310130c..e5b49786 100644 --- a/payment/models.py +++ b/payment/models.py @@ -454,7 +454,7 @@ class Account(models.Model): # fire off an account_expiring notice -- might not want to do this immediately - notification.send([self.user], "account_expiring", { + notification.queue([self.user], "account_expiring", { 'user': self.user, 'site':Site.objects.get_current() }, True) @@ -463,7 +463,7 @@ class Account(models.Model): logger.info( "EXPIRING. send to instance.user: %s site: %s", self.user, Site.objects.get_current()) - notification.send([self.user], "account_expired", { + notification.queue([self.user], "account_expired", { 'user': self.user, 'site':Site.objects.get_current() }, True) diff --git a/payment/signals.py b/payment/signals.py index 4af55c05..5c9499cd 100644 --- a/payment/signals.py +++ b/payment/signals.py @@ -38,6 +38,8 @@ def handle_credit_balance(sender, amount=0, **kwargs): 'amount':amount, 'minus_amount':-amount }, True) + from regluit.core.tasks import emit_notifications + emit_notifications.delay() # successful_campaign -> send notices credit_balance_added.connect(handle_credit_balance) \ No newline at end of file diff --git a/payment/tasks.py b/payment/tasks.py index c532dfa0..2febd582 100644 --- a/payment/tasks.py +++ b/payment/tasks.py @@ -42,6 +42,10 @@ def update_account_status(all_accounts=True, send_notice_on_change_only=True): except Exception, e: errors.append(e) + # fire off notices + + from regluit.core.tasks import emit_notifications + emit_notifications.delay() return errors diff --git a/requirements_versioned.pip b/requirements_versioned.pip index dca571ed..490c5757 100644 --- a/requirements_versioned.pip +++ b/requirements_versioned.pip @@ -32,7 +32,8 @@ django-kombu==0.9.4 django-maintenancemode==0.10 django-mptt==0.7.4 django-nose-selenium==0.7.3 -git+git://github.com/transifex/django-notification.git@9c357489bc018180c149f1fd07509326ff15113c +#django-notification==0.2 +git+git://github.com/eshellman/django-notification.git@8bb7afbbb07e8cad74bc1cf17e0ac6fc117c0497 django-registration==1.0 django-selectable==0.7.0 django-smtp-ssl==1.0