Ejemplo n.º 1
0
 def _render_content(self, request, pk, template):
     order = self.get_object(request, pk)
     context = {'request': request, 'render_label': 'print'}
     customer_serializer = app_settings.CUSTOMER_SERIALIZER(order.customer)
     order_serializer = OrderDetailSerializer(order, context=context)
     return template.render(context={
         'customer': customer_serializer.data,
         'order': order_serializer.data,
         'object': order,
     }, request=request)
Ejemplo n.º 2
0
 def _render_letter(self, request, pk, template):
     order = self.get_object(request, pk)
     context = {'request': request, 'render_label': 'print'}
     customer_serializer = app_settings.CUSTOMER_SERIALIZER(order.customer)
     order_serializer = OrderDetailSerializer(order, context=context)
     content = template.render(RequestContext(request, {
         'customer': customer_serializer.data,
         'data': order_serializer.data,
         'order': order,
     }))
     return HttpResponse(content)
Ejemplo n.º 3
0
def transition_change_notification(order):
    """
    This function shall be called, after an Order object performed a transition change.

    """
    if not isinstance(order, BaseOrder):
        raise TypeError("Object order must inherit from class BaseOrder")
    emails_in_queue = False
    for notification in Notification.objects.filter(
            transition_target=order.status):
        recipient = notification.get_recipient(order)
        if recipient is None:
            continue

        # emulate a request object which behaves similar to that one, when the customer submitted its order
        emulated_request = EmulateHttpRequest(order.customer,
                                              order.stored_request)
        customer_serializer = app_settings.CUSTOMER_SERIALIZER(order.customer)
        render_context = {'request': emulated_request, 'render_label': 'email'}
        order_serializer = OrderDetailSerializer(order, context=render_context)
        language = order.stored_request.get('language')
        context = {
            'customer': customer_serializer.data,
            'order': order_serializer.data,
            'ABSOLUTE_BASE_URI':
            emulated_request.build_absolute_uri().rstrip('/'),
            'render_language': language,
        }
        try:
            latest_delivery = order.delivery_set.latest()
            context['latest_delivery'] = DeliverySerializer(
                latest_delivery, context=render_context).data
        except (AttributeError, models.ObjectDoesNotExist):
            pass
        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=template,
                  context=context,
                  attachments=attachments,
                  render_on_delivery=True)
        emails_in_queue = True
    if emails_in_queue:
        email_queued()
Ejemplo n.º 4
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'}
     customer_serializer = app_settings.CUSTOMER_SERIALIZER(delivery.order.customer)
     order_serializer = OrderDetailSerializer(delivery.order, context=context)
     content = template.render(RequestContext(request, {
         'customer': customer_serializer.data,
         'data': order_serializer.data,
         'delivery': delivery,
     }))
     return HttpResponse(content)
Ejemplo n.º 5
0
def order_event_notification(sender, instance=None, target=None, **kwargs):
    from shop.models.order import OrderModel
    from shop.serializers.order import OrderDetailSerializer

    if not isinstance(instance, OrderModel):
        return
    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)
        customer_serializer = app_settings.CUSTOMER_SERIALIZER(
            instance.customer)
        order_serializer = OrderDetailSerializer(
            instance, context={'request': emulated_request})
        language = instance.stored_request.get('language')
        context = {
            'customer': customer_serializer.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)