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.

oscar_generate_email_content.py 1.1KB

123456789101112131415161718192021222324252627282930
  1. from django.core.management.base import BaseCommand, CommandError
  2. from oscar.core.loading import get_model
  3. from oscar.core.loading import get_class
  4. Order = get_model('order', 'Order')
  5. CommunicationEventType = get_model('customer', 'CommunicationEventType')
  6. Dispatcher = get_class('customer.utils', 'Dispatcher')
  7. class Command(BaseCommand):
  8. args = '<communication_event_type> <order number>'
  9. help = 'For testing the content of order emails'
  10. def handle(self, *args, **options):
  11. if len(args) != 2:
  12. raise CommandError("Please select a event type and order number")
  13. try:
  14. order = Order.objects.get(number=args[1])
  15. except Order.DoesNotExist:
  16. raise CommandError("No order found with number %s" % args[1])
  17. ctx = {
  18. 'order': order,
  19. 'lines': order.lines.all(),
  20. }
  21. messages = CommunicationEventType.objects.get_and_render(
  22. args[0], ctx)
  23. print("Subject: %s\nBody:\n\n%s\nBody HTML:\n\n%s" % (
  24. messages['subject'], messages['body'], messages['html']))