Beispiel #1
0
    def result_data(self):
        extended_context = copy(self.context)

        extended_context.update({
            'template': get_template_with_base_path(self.template_path),
            'url_paginator': self.url_paginator,
        })

        extended_context.update(self.get_paged_data())

        return extended_context
Beispiel #2
0
def b2c_products_special(context, template_name, on_page):
    usersite, template, organization = get_usersite_objects()

    if template.typeof == 1:
        children = organization.children.all()
        queryset = B2CProduct.get_active_objects().filter(company__in=children).order_by('?')[:3]
    else:
        if isinstance(organization, Company):
            queryset = B2CProduct.get_active_objects().filter(company=organization).order_by('?')[:3]
        else:
            queryset = B2CProduct.objects.none()

    return {
            'template': get_template_with_base_path(template_name),
            'products': queryset
        }
Beispiel #3
0
    def get(self, request):
        # Корзина
        basket = Basket(request)

        # Действия
        del_product = request.GET.get('del')
        clean = request.GET.get('clean')

        # Сколько наименований товаров в Корзине
        basket_items_total = len(list(basket))

        # Набор информации для PayPal
        paypal_dict = {}
        if basket_items_total > 1:
            paypal_dict.update({
                'cmd':
                '_cart',
                'upload':
                1,
                'business':
                basket.paypal,
                'notify_url':
                '{0}://{1}{2}'.format(request.scheme,
                                      self.usersite.site.domain,
                                      reverse('paypal-ipn')),
                'return_url':
                request.build_absolute_uri(),
                'cancel_return':
                request.build_absolute_uri(),
                'no_shipping':
                0,
                'quantity':
                1,
                'currency_code':
                basket.currency
            })
            i = 1
            for item in basket:
                paypal_dict['amount_%d' % i] = \
                    item.product.get_discount_price() * item.quantity
                paypal_dict['item_name_%d' % i] = item.product.name
                i += 1
            paypal_form = PayPalBasketForm(basket, initial=paypal_dict)

        else:
            if basket.summary():
                paypal_dict.update({
                    'business':
                    basket.paypal,
                    'amount':
                    basket.summary(),
                    'notify_url':
                    '{0}://{1}{2}'.format(self.request.scheme,
                                          self.usersite.site.domain,
                                          reverse('paypal-ipn')),
                    'return_url':
                    request.build_absolute_uri(),
                    'cancel_return':
                    request.build_absolute_uri(),
                    'item_name':
                    _('Products from website ') + self.usersite.site.domain,
                    'no_shipping':
                    0,
                    'quantity':
                    1,
                    'currency_code':
                    basket.currency
                })
            paypal_form = PayPalPaymentsForm(initial=paypal_dict)

        data = {
            'title': _('B2C Basket'),
            'basket': dict(src=basket),
            'total': basket.summary(),
            'paypal_form': paypal_form,
        }

        # Delete product form basket
        if del_product:
            product = B2CProduct.objects.get(id=del_product)
            basket.remove(product)
            return HttpResponseRedirect((reverse('b2c_products:basket')))

        # # Clean basket
        if clean:
            if clean.isdigit():
                basket.clear()
                return HttpResponseRedirect((reverse('b2c_products:basket')))
            return HttpResponseNotFound()
        return render(request, get_template_with_base_path(self.template_name),
                      data)
Beispiel #4
0
def render_page(request, template, **kwargs):
    return render(request, get_template_with_base_path(template), kwargs)