revert to older, patched Notification

pull/1/head
eric 2016-04-08 18:45:50 -04:00
parent 14829c327a
commit a4e9855b35
13 changed files with 58 additions and 19 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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', <User: dataunbound>, datetime.datetime(2012, 11, 21, 18, 33, 15)),

View File

@ -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

View File

@ -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"
]
},
{

View File

@ -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)"

View File

@ -144,6 +144,7 @@ Account.objects.filter(status='EXPIRED')
# <codecell>
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
# <codecell>
notification.send([me], "account_expiring", {
notification.send_now([me], "account_expiring", {
'user': me,
'site':Site.objects.get_current()
}, True)
# <codecell>
notification.send([me], "account_expired", {
notification.send_now([me], "account_expired", {
'user': me,
'site':Site.objects.get_current()
}, True)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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