make sure to queue the notification emmisions

so that we don't need the emit_notices cron job
pull/91/head
eric 2018-06-20 15:57:34 -04:00
parent cc74d7d414
commit e82c389236
5 changed files with 15 additions and 6 deletions

View File

@ -319,14 +319,17 @@ class Acq(models.Model):
self.expire_in(timedelta(days=14))
self.user.wishlist.add_work(self.work, "borrow")
notification.send([self.user], "library_borrow", {'acq':self})
return self
result = self
elif self.borrowable and user:
user.wishlist.add_work(self.work, "borrow")
borrowed = Acq.objects.create(user=user, work=self.work, license=BORROWED, lib_acq=self)
from regluit.core.tasks import watermark_acq
notification.send([user], "library_borrow", {'acq':borrowed})
watermark_acq.delay(borrowed)
return borrowed
result = borrowed
from regluit.core.tasks import emit_notifications
emit_notifications.delay()
return result
@property
def borrowable(self):
@ -1372,6 +1375,9 @@ class Gift(models.Model):
self.used = now()
self.save()
notification.send([self.giver], "purchase_got_gift", {'gift': self}, True)
from regluit.core.tasks import emit_notifications
emit_notifications.delay()
# this was causing a circular import problem and we do not seem to be using

View File

@ -109,5 +109,7 @@ def notify_rh(sender, created, instance, **kwargs):
for claim in instance.claim.filter(status='pending'):
claim.status = 'active'
claim.save()
from regluit.core.tasks import emit_notifications
emit_notifications.delay()
post_save.connect(notify_rh, sender=RightsHolder)

View File

@ -212,9 +212,8 @@ 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()
from regluit.core.tasks import emit_notifications
emit_notifications.delay()
transaction_charged.connect(handle_transaction_charged)

View File

@ -173,7 +173,7 @@ def refresh_acqs():
# notify the user with the hold
if 'example.org' not in reserve_acq.user.email:
notification.send([reserve_acq.user], "library_reserve", {'acq':reserve_acq})
notification.send_now([reserve_acq.user], "library_reserve", {'acq':reserve_acq})
# delete the hold
hold.delete()
break

View File

@ -2876,6 +2876,8 @@ def receive_gift(request, nonce):
gift.acq.expire_in(0)
gift.use()
notification.send([giftee], "purchase_gift", context, True)
from regluit.core.tasks import emit_notifications
emit_notifications.delay()
return render(request, 'gift_duplicate.html', context)
context['form'] = RegiftForm()
return render(request, 'gift_duplicate.html', context)