You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

receivers.py 944B

12345678910111213141516171819202122232425262728
  1. from django.conf import settings
  2. from django.db.models import get_model
  3. from django.db.models.signals import post_save
  4. from django.contrib.auth.models import User
  5. def send_product_alerts(sender, instance, created, **kwargs):
  6. from oscar.apps.customer.alerts import utils
  7. utils.send_product_alerts(instance.product)
  8. def migrate_alerts_to_user(sender, instance, created, **kwargs):
  9. """
  10. Transfer any active alerts linked to a user's email address to the newly
  11. registered user.
  12. """
  13. if created:
  14. ProductAlert = get_model('customer', 'ProductAlert')
  15. alerts = ProductAlert.objects.filter(email=instance.email, status=ProductAlert.ACTIVE)
  16. alerts.update(user=instance, key=None, email=None)
  17. post_save.connect(migrate_alerts_to_user, sender=User)
  18. if settings.OSCAR_EAGER_ALERTS:
  19. StockRecord = get_model('partner', 'StockRecord')
  20. post_save.connect(send_product_alerts, sender=StockRecord)