diff --git a/core/models/__init__.py b/core/models/__init__.py index f3795655..662ddca3 100755 --- a/core/models/__init__.py +++ b/core/models/__init__.py @@ -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 diff --git a/core/models/rh_models.py b/core/models/rh_models.py index 792e729b..72ca471b 100644 --- a/core/models/rh_models.py +++ b/core/models/rh_models.py @@ -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) diff --git a/core/signals.py b/core/signals.py index ea17ac4f..96f94cf1 100644 --- a/core/signals.py +++ b/core/signals.py @@ -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) diff --git a/core/tasks.py b/core/tasks.py index 7095d5d6..36dc8f2b 100644 --- a/core/tasks.py +++ b/core/tasks.py @@ -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 diff --git a/frontend/views/__init__.py b/frontend/views/__init__.py index 4b0b65db..84e764bc 100755 --- a/frontend/views/__init__.py +++ b/frontend/views/__init__.py @@ -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)