Пример #1
0
def order_event_notification(sender, instance=None, target=None, **kwargs):
    from shop.rest import serializers

    for notification in Notification.objects.filter(transition_target=target):
        recipient = notification.get_recipient(instance)
        if recipient is None:
            continue

        # emulate a request object which behaves similar to that one, when the customer submitted its order
        emulated_request = EmulateHttpRequest(instance.customer,
                                              instance.stored_request)
        order_serializer = serializers.OrderDetailSerializer(
            instance, context={'request': emulated_request})
        language = instance.stored_request.get('language')
        context = {
            'customer': serializers.CustomerSerializer(instance.customer).data,
            'data': order_serializer.data,
            'ABSOLUTE_BASE_URI':
            emulated_request.build_absolute_uri().rstrip('/'),
            'render_language': language,
        }
        try:
            template = notification.mail_template.translated_templates.get(
                language=language)
        except EmailTemplate.DoesNotExist:
            template = notification.mail_template
        attachments = {}
        for notiatt in notification.notificationattachment_set.all():
            attachments[notiatt.attachment.
                        original_filename] = notiatt.attachment.file.file
        mail.send(recipient,
                  template=notification.mail_template,
                  context=context,
                  attachments=attachments,
                  render_on_delivery=True)
Пример #2
0
 def _render_letter(self, request, pk, template):
     order = self.get_object(request, pk)
     context = {'request': request, 'render_label': 'print'}
     order_serializer = serializers.OrderDetailSerializer(order, context=context)
     content = template.render(RequestContext(request, {
         'customer': serializers.CustomerSerializer(order.customer).data,
         'data': order_serializer.data,
         'order': order,
     }))
     return HttpResponse(content)
Пример #3
0
 def render_delivery_note(self, request, delivery_pk=None):
     template = select_template([
         '{}/print/delivery-note.html'.format(app_settings.APP_LABEL.lower()),
         'shop/print/delivery-note.html'
     ])
     delivery = DeliveryModel.objects.get(pk=delivery_pk)
     context = {'request': request, 'render_label': 'print'}
     order_serializer = serializers.OrderDetailSerializer(delivery.order, context=context)
     content = template.render(RequestContext(request, {
         'customer': serializers.CustomerSerializer(delivery.order.customer).data,
         'data': order_serializer.data,
         'delivery': delivery,
     }))
     return HttpResponse(content)