Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

oscar_send_notifications.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import logging
  2. from django.db.models import get_model
  3. from django.utils.translation import ugettext_lazy as _
  4. from django.core.management.base import NoArgsCommand
  5. from oscar.apps.catalogue.notification import utils
  6. Product = get_model('catalogue', 'product')
  7. ProductNotification = get_model('notification', 'productnotification')
  8. logger = logging.getLogger(__name__)
  9. class Command(NoArgsCommand):
  10. """
  11. Check stock records of products for availability and send out notifications
  12. to customers that have subscribed to a notification email. Notifications
  13. for available products are disabled after an email has been send out.
  14. """
  15. help = _("Check check for notifications of products that are back in "
  16. "stock, send out emails and deactivate the notifications")
  17. def handle_noargs(self, **options):
  18. """
  19. Check all products with active product notifications for
  20. availability and send out email notifications when a product is
  21. available to buy.
  22. """
  23. logger.info('start searching for updated stock records')
  24. products = Product.objects.filter(
  25. productnotification__status=ProductNotification.ACTIVE
  26. )
  27. for product in products:
  28. logger.info('checking product availability for %s', product)
  29. if product.is_available_to_buy:
  30. logger.info('sending notifications for product %s', product)
  31. utils.send_email_notifications_for_product(product)