示例#1
0
文件: cms_apps.py 项目: bwrm/alby
    def get_urls(self, page=None, language=None, **kwargs):
        from shop.search.views import CMSPageCatalogWrapper
        from shop.views.catalog import AddToCartView, ProductRetrieveView
        from alby.serializers import CatalogSearchSerializer, RebateAddToCartSerializer, AddSofaToCartSerializer, UpdateDataSerialiser

        return [
            url(
                r'^$',
                CMSPageCatalogWrapper.as_view(
                    search_serializer_class=CatalogSearchSerializer, )),
            url(r'^(?P<slug>[\w-]+)/add-to-cart', AddToCartView.as_view()),
            url(
                r'^(?P<slug>[\w-]+)/get-rebate',
                AddToCartView.as_view(
                    serializer_class=RebateAddToCartSerializer, )),
            url(
                r'^(?P<slug>[\w-]+)/add-sofa-to-cart',
                AddToCartView.as_view(
                    serializer_class=AddSofaToCartSerializer, )),
            url(
                r'^(?P<slug>[\w-]+)/update-small-data',
                UpdateDataView.as_view(
                    serializer_class=UpdateDataSerialiser, )),
            url(
                r'^/divany/(?P<slug>[\w-]+)',
                ProductRetrieveView.as_view(
                    use_modal_dialog=False,
                    serializer_class=CustomizedProductSerializer,
                )),
            url(r'^(?P<slug>[\w-]+)',
                ProductRetrieveView.as_view(use_modal_dialog=False, )),
        ]
示例#2
0
    def get_urls(self, page=None, language=None, **kwargs):
        from shop.search.mixins import ProductSearchViewMixin
        from shop.views.catalog import AddToCartView, ProductListView, ProductRetrieveView
        from shop.views.catalog import AddFilterContextMixin
        from myshop.filters import ManufacturerFilterSet
        from myshop.serializers import AddSmartPhoneToCartSerializer

        ProductListView = type(
            'ProductSearchListView',
            (AddFilterContextMixin, ProductSearchViewMixin, ProductListView),
            {})
        filter_backends = [CMSPagesFilterBackend]
        filter_backends.extend(api_settings.DEFAULT_FILTER_BACKENDS)
        return [
            url(r'^(?P<slug>[\w-]+)/add-to-cart', AddToCartView.as_view()),
            url(
                r'^(?P<slug>[\w-]+)/add-smartphone-to-cart',
                AddToCartView.as_view(
                    serializer_class=AddSmartPhoneToCartSerializer, )),
            url(r'^(?P<slug>[\w-]+)',
                ProductRetrieveView.as_view(use_modal_dialog=False, )),
            url(
                r'^',
                ProductListView.as_view(
                    filter_backends=filter_backends,
                    filter_class=ManufacturerFilterSet,
                )),
        ]
示例#3
0
    def get_urls(self, page=None, language=None, **kwargs):
        from shop.search.views import CMSPageCatalogWrapper
        from shop.views.catalog import AddToCartView, ProductRetrieveView
        from myshop.filters import ManufacturerFilterSet
        from myshop.serializers import AddSmartPhoneToCartSerializer, CatalogSearchSerializer

        return [
            url(r'^$', CMSPageCatalogWrapper.as_view(
                filter_class=ManufacturerFilterSet,
                search_serializer_class=CatalogSearchSerializer,
            )),
            url(r'^(?P<slug>[\w-]+)/?$', ProductRetrieveView.as_view()),
            url(r'^(?P<slug>[\w-]+)/add-to-cart', AddToCartView.as_view()),
            url(r'^(?P<slug>[\w-]+)/add-smartphone-to-cart', AddToCartView.as_view(
                serializer_class=AddSmartPhoneToCartSerializer,
            )),
        ]
示例#4
0
def test_get_add_to_cart(commodity_factory, customer_factory, rf):
    product = commodity_factory()
    request = rf.get(product.get_absolute_url() + '/add-to-cart')
    request.current_page = product.cms_pages.first()
    request.customer = customer_factory()
    response = AddToCartView.as_view()(request, slug=product.slug)
    response.render()
    assert response.data['quantity'] == 1
    assert response.data['unit_price'] == six.text_type(product.unit_price)
    assert response.data['product_code'] == product.product_code
    assert response.data['is_in_cart'] is False
示例#5
0
def test_too_greedy(commodity_factory, customer_factory, rf):
    """
    Add more products to the cart than quantity in stock
    """
    product = commodity_factory()
    data = {'quantity': 10, 'product': product.id}
    request = rf.post(product.get_absolute_url() + '/add-to-cart', data=data)
    request.current_page = product.cms_pages.first()
    request.customer = customer_factory()
    response = AddToCartView.as_view()(request, slug=product.slug)
    assert response.status_code == 202
    assert response.data['quantity'] == 5  # not 10, as requested
    assert response.data['unit_price'] == six.text_type(product.unit_price)
    assert response.data['subtotal'] == six.text_type(5 * product.unit_price)
示例#6
0
    def get_urls(self, page=None, language=None, **kwargs):
        from shop.views.catalog import AddToCartView, ProductListView, ProductRetrieveView
        from giftshop.serializers import ProductDetailSerializer

        return [
            url(r'^$',
                ProductListView.as_view(redirect_to_lonely_product=True, )),
            url(
                r'^(?P<slug>[\w-]+)/?$',
                ProductRetrieveView.as_view(
                    serializer_class=ProductDetailSerializer,
                    lookup_field='translations__slug')),
            url(r'^(?P<slug>[\w-]+)/add-to-cart',
                AddToCartView.as_view(lookup_field='translations__slug')),
        ]
示例#7
0
    def get_urls(self, page=None, language=None, **kwargs):
        from shop.search.mixins import ProductSearchViewMixin
        from shop.views.catalog import AddToCartView, ProductListView, ProductRetrieveView
        from myshop.serializers import ProductDetailSerializer

        ProductListView = type('ProductSearchListView',
                               (ProductSearchViewMixin, ProductListView), {})
        return [
            url(r'^(?P<slug>[\w-]+)/add-to-cart', AddToCartView.as_view()),
            url(
                r'^(?P<slug>[\w-]+)',
                ProductRetrieveView.as_view(
                    serializer_class=ProductDetailSerializer, )),
            url(r'^',
                ProductListView.as_view(redirect_to_lonely_product=True, )),
        ]
示例#8
0
    def get_urls(self, page=None, language=None, **kwargs):

        filter_backends = [CMSPagesFilterBackend]
        filter_backends.extend(api_settings.DEFAULT_FILTER_BACKENDS)
        ProductListViewClass = type('ProductSearchListView',
                                    (ProductSearchViewMixin, ProductListView),
                                    {})
        return [
            url(r'^(?P<slug>[\w-]+)/add-to-cart', AddToCartView.as_view()),
            url(
                r'^(?P<slug>[\w-]+)',
                ProductRetrieveView.as_view(
                    serializer_class=ProductDetailSerializer, )),
            url(
                r'^',
                ProductListViewClass.as_view(
                    filter_backends=filter_backends,
                    redirect_to_lonely_product=True,
                )),
        ]
示例#9
0
from cms.apphook_pool import apphook_pool
from cms.cms_menus import SoftRootCutter
from menus.menu_pool import menu_pool
from shop.cms_apphooks import CatalogListCMSApp, CatalogSearchCMSApp, OrderApp, PasswordResetApp


class CatalogListApp(CatalogListCMSApp):
    def get_urls(self, page=None, language=None, **kwargs):
{%- if cookiecutter.products_model == 'polymorphic' %}
        from shop.search.views import CMSPageCatalogWrapper
        from shop.views.catalog import AddToCartView, ProductRetrieveView
        from {{ cookiecutter.app_name }}.filters import ManufacturerFilterSet
        from {{ cookiecutter.app_name }}.serializers import AddSmartPhoneToCartSerializer, CatalogSearchSerializer

        return [
            url(r'^(?P<slug>[\w-]+)/add-to-cart', AddToCartView.as_view()),
            url(r'^(?P<slug>[\w-]+)/add-smartphone-to-cart', AddToCartView.as_view(
                serializer_class=AddSmartPhoneToCartSerializer,
            )),
            url(r'^(?P<slug>[\w-]+)', ProductRetrieveView.as_view(
                use_modal_dialog=False,
            )),
            url(r'^', CMSPageCatalogWrapper.as_view(
                filter_class=ManufacturerFilterSet,
                search_serializer_class=CatalogSearchSerializer,
            )),
        ]
{%- else %}{% set use_lookup_field = (cookiecutter.products_model == 'commodity' and cookiecutter.use_i18n == 'y') %}
        from shop.views.catalog import AddToCartView, ProductListView, ProductRetrieveView
        from {{ cookiecutter.app_name }}.serializers import ProductDetailSerializer
# -*- coding: utf-8 -*-
"""
These URL routings are used by the example `i18n_commodity` as found in the django-SHOP's tutorials.
The difference here is that we modified the lookup_field for slug, since it is translated.
"""
from __future__ import unicode_literals

from django.conf.urls import url

from shop.views.catalog import ProductListView, ProductRetrieveView, AddToCartView

from tlmshop.serializers import ProductSummarySerializer, ProductDetailSerializer

urlpatterns = [
    url(r'^$', ProductListView.as_view(
        serializer_class=ProductSummarySerializer,
    )),
    url(r'^(?P<slug>[\w-]+)/?$', ProductRetrieveView.as_view(
        serializer_class=ProductDetailSerializer,
        lookup_field='translations__slug'
    )),
    url(r'^(?P<slug>[\w-]+)/add-to-cart', AddToCartView.as_view(
        lookup_field='translations__slug'
    )),
]
示例#11
0
# -*- coding: utf-8 -*-
"""
These URL routings are used by the example `i18n_commodity` as found in the django-SHOP's tutorials.
The difference here is that we modified the lookup_field for slug, since it is translated.
"""
from __future__ import unicode_literals

from django.conf.urls import url

from shop.views.catalog import ProductListView, ProductRetrieveView, AddToCartView

from myshop.serializers import ProductSummarySerializer, ProductDetailSerializer

urlpatterns = [
    url(r'^$',
        ProductListView.as_view(serializer_class=ProductSummarySerializer, )),
    url(
        r'^(?P<slug>[\w-]+)/?$',
        ProductRetrieveView.as_view(serializer_class=ProductDetailSerializer,
                                    lookup_field='translations__slug')),
    url(r'^(?P<slug>[\w-]+)/add-to-cart',
        AddToCartView.as_view(lookup_field='translations__slug')),
]
                                ProductDetailSerializer,
                                AddSmartCardToCartSerializer,
                                AddSmartPhoneToCartSerializer,
                                CatalogSearchSerializer)

filter_backends = list(api_settings.DEFAULT_FILTER_BACKENDS)
filter_backends.append(CMSPagesFilterBackend())

urlpatterns = patterns(
    '',
    url(
        r'^$',
        ProductListView.as_view(
            serializer_class=ProductSummarySerializer,
            filter_backends=filter_backends,
        )),
    url(r'^search-catalog$',
        SearchView.as_view(serializer_class=CatalogSearchSerializer, )),
    url(
        r'^(?P<slug>[\w-]+)$',
        ProductRetrieveView.as_view(
            serializer_class=ProductDetailSerializer, )),
    url(r'^(?P<slug>[\w-]+)/add-to-cart',
        AddToCartView.as_view(
            serializer_class=AddSmartCardToCartSerializer, )),
    url(
        r'^(?P<slug>[\w-]+)/add-smartphone-to-cart',
        AddToCartView.as_view(
            serializer_class=AddSmartPhoneToCartSerializer, )),
)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
These URL routings are used by the example `commodity`, `smartcard` and `i18n_smartcard` as found
in the django-SHOP's tutorials.
This is the simplest way of routing and a good default to start with.
"""

from django.conf.urls import url
from shop.views.catalog import AddToCartView, CMSPageProductListView, ProductRetrieveView
from shop.search.views import SearchView
from myshop.serializers import (ProductSummarySerializer,
                                ProductDetailSerializer,
                                CatalogSearchSerializer)

urlpatterns = [
    url(
        r'^$',
        CMSPageProductListView.as_view(
            serializer_class=ProductSummarySerializer, )),
    url(r'^search-catalog$',
        SearchView.as_view(serializer_class=CatalogSearchSerializer, )),
    url(r'^(?P<slug>[\w-]+)/?$',
        ProductRetrieveView.as_view(serializer_class=ProductDetailSerializer)),
    url(r'^(?P<slug>[\w-]+)/add-to-cart', AddToCartView.as_view()),
]
示例#14
0
# -*- coding: utf-8 -*-
"""
These URL routings are used by the example `i18n_commodity` as found in the django-SHOP's tutorials.
The difference here is that we modified the lookup_field for slug, since it is translated.
"""
from __future__ import unicode_literals

from django.conf.urls import url

from shop.views.catalog import ProductListView, ProductRetrieveView, AddToCartView

from myshop.serializers import ProductSummarySerializer, ProductDetailSerializer

urlpatterns = [
    url(r'^$', ProductListView.as_view(
        serializer_class=ProductSummarySerializer,
    )),
    url(r'^(?P<slug>[\w-]+)/?$', ProductRetrieveView.as_view(
        serializer_class=ProductDetailSerializer,
        lookup_field='translations__slug'
    )),
    url(r'^(?P<slug>[\w-]+)/add-to-cart', AddToCartView.as_view(
        lookup_field='translations__slug'
    )),
]
from django.conf.urls import patterns, url
from rest_framework.settings import api_settings
from shop.rest.filters import CMSPagesFilterBackend
from shop.views.catalog import AddToCartView, ProductListView, ProductRetrieveView
from shop.search.views import SearchView
from myshop.serializers import (ProductSummarySerializer, ProductDetailSerializer,
    AddSmartCardToCartSerializer, AddSmartPhoneToCartSerializer, CatalogSearchSerializer)

filter_backends = list(api_settings.DEFAULT_FILTER_BACKENDS)
filter_backends.append(CMSPagesFilterBackend())

urlpatterns = patterns('',
    url(r'^$', ProductListView.as_view(
        serializer_class=ProductSummarySerializer,
        filter_backends=filter_backends,
    )),
    url(r'^search-catalog$', SearchView.as_view(
        serializer_class=CatalogSearchSerializer,
    )),
    url(r'^(?P<slug>[\w-]+)$', ProductRetrieveView.as_view(
        serializer_class=ProductDetailSerializer,
    )),
    url(r'^(?P<slug>[\w-]+)/add-to-cart', AddToCartView.as_view(
        serializer_class=AddSmartCardToCartSerializer,
    )),
    url(r'^(?P<slug>[\w-]+)/add-smartphone-to-cart', AddToCartView.as_view(
        serializer_class=AddSmartPhoneToCartSerializer,
    )),
)
示例#16
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf.urls import patterns, url
from rest_framework.settings import api_settings
from shop.rest.filters import CMSPagesFilterBackend
from shop.views.catalog import AddToCartView, ProductListView, ProductRetrieveView
from shop.search.views import SearchView
from myshop.serializers import ProductSummarySerializer, ProductDetailSerializer, CatalogSearchSerializer

filter_backends = list(api_settings.DEFAULT_FILTER_BACKENDS)
filter_backends.append(CMSPagesFilterBackend())

urlpatterns = patterns(
    "",
    url(r"^$", ProductListView.as_view(serializer_class=ProductSummarySerializer, filter_backends=filter_backends)),
    url(r"^search-catalog$", SearchView.as_view(serializer_class=CatalogSearchSerializer)),
    url(r"^(?P<slug>[\w-]+)$", ProductRetrieveView.as_view(serializer_class=ProductDetailSerializer)),
    url(r"^(?P<slug>[\w-]+)/add-to-cart", AddToCartView.as_view()),
)
示例#17
0
    def get_urls(self, page=None, language=None, **kwargs):
{%- if cookiecutter.products_model == 'polymorphic' %}
        from shop.search.views import CMSPageCatalogWrapper
        from shop.views.catalog import AddToCartView, ProductRetrieveView
        from {{ cookiecutter.app_name }}.filters import ManufacturerFilterSet
        from {{ cookiecutter.app_name }}.serializers import AddSmartPhoneToCartSerializer, CatalogSearchSerializer

        return [
            url(r'^$', CMSPageCatalogWrapper.as_view(
                filter_class=ManufacturerFilterSet,
                search_serializer_class=CatalogSearchSerializer,
            )),
            url(r'^(?P<slug>[\w-]+)/?$', ProductRetrieveView.as_view(
                use_modal_dialog=False,
            )),
            url(r'^(?P<slug>[\w-]+)/add-to-cart', AddToCartView.as_view()),
            url(r'^(?P<slug>[\w-]+)/add-smartphone-to-cart', AddToCartView.as_view(
                serializer_class=AddSmartPhoneToCartSerializer,
            )),
        ]
{%- elif cookiecutter.products_model == 'commodity' and cookiecutter.use_i18n == 'y' %}
        from shop.views.catalog import AddToCartView, ProductListView, ProductRetrieveView
        from {{ cookiecutter.app_name }}.serializers import ProductSummarySerializer, ProductDetailSerializer

        return [
            url(r'^$', ProductListView.as_view(
                serializer_class=ProductSummarySerializer,
                redirect_to_lonely_product=True,
            )),
            url(r'^(?P<slug>[\w-]+)/?$', ProductRetrieveView.as_view(
                use_modal_dialog=False,