Merge pull request #790 from Gluejar/queue-notifications

make sure to queue the notification emisions
pull/91/head
eshellman 2018-06-20 16:18:03 -04:00 committed by GitHub
commit 1389f87616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.expire_in(timedelta(days=14))
self.user.wishlist.add_work(self.work, "borrow") self.user.wishlist.add_work(self.work, "borrow")
notification.send([self.user], "library_borrow", {'acq':self}) notification.send([self.user], "library_borrow", {'acq':self})
return self result = self
elif self.borrowable and user: elif self.borrowable and user:
user.wishlist.add_work(self.work, "borrow") user.wishlist.add_work(self.work, "borrow")
borrowed = Acq.objects.create(user=user, work=self.work, license=BORROWED, lib_acq=self) borrowed = Acq.objects.create(user=user, work=self.work, license=BORROWED, lib_acq=self)
from regluit.core.tasks import watermark_acq from regluit.core.tasks import watermark_acq
notification.send([user], "library_borrow", {'acq':borrowed}) notification.send([user], "library_borrow", {'acq':borrowed})
watermark_acq.delay(borrowed) watermark_acq.delay(borrowed)
return borrowed result = borrowed
from regluit.core.tasks import emit_notifications
emit_notifications.delay()
return result
@property @property
def borrowable(self): def borrowable(self):
@ -1372,6 +1375,9 @@ class Gift(models.Model):
self.used = now() self.used = now()
self.save() self.save()
notification.send([self.giver], "purchase_got_gift", {'gift': self}, True) 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 # 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'): for claim in instance.claim.filter(status='pending'):
claim.status = 'active' claim.status = 'active'
claim.save() claim.save()
from regluit.core.tasks import emit_notifications
emit_notifications.delay()
post_save.connect(notify_rh, sender=RightsHolder) 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 from regluit.core.tasks import send_mail_task
message = render_to_string("notification/purchase_complete/full.txt", context ) message = render_to_string("notification/purchase_complete/full.txt", context )
send_mail_task.delay('unglue.it transaction confirmation', message, 'notices@gluejar.com', [transaction.receipt]) send_mail_task.delay('unglue.it transaction confirmation', message, 'notices@gluejar.com', [transaction.receipt])
if transaction.user: from regluit.core.tasks import emit_notifications
from regluit.core.tasks import emit_notifications emit_notifications.delay()
emit_notifications.delay()
transaction_charged.connect(handle_transaction_charged) transaction_charged.connect(handle_transaction_charged)

View File

@ -173,7 +173,7 @@ def refresh_acqs():
# notify the user with the hold # notify the user with the hold
if 'example.org' not in reserve_acq.user.email: 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 # delete the hold
hold.delete() hold.delete()
break break

View File

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