Example #1
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,
                )),
        ]
Example #2
0
def test_catalog_list(commodity_factory, rf):
    product = commodity_factory()
    request = rf.get('/catalog/')
    request.current_page = product.cms_pages.first()
    response = ProductListView.as_view()(request)
    response.render()
    assert response.data['count'] == 1
    assert response.data['next'] is None
    assert len(response.data['results']) == 1
    assert response.data['results'][0][
        'product_url'] == request.path + product.slug
Example #3
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')),
        ]
Example #4
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, )),
        ]
# -*- 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()),
)
Example #6
0
            )),
        ]
{%- 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

        return [
            url(r'^(?P<slug>[\w-]+)/add-to-cart', AddToCartView.as_view({% if use_lookup_field %}lookup_field='translations__slug'{% endif %})),
            url(r'^(?P<slug>[\w-]+)', ProductRetrieveView.as_view(
                serializer_class=ProductDetailSerializer,
    {%- if use_lookup_field %}
                lookup_field='translations__slug'
    {%- endif %}
            )),
            url(r'^', ProductListView.as_view(
                redirect_to_lonely_product=True,
            )),
        ]
{%- endif %}

apphook_pool.register(CatalogListApp)


class CatalogSearchApp(CatalogSearchCMSApp):
    def get_urls(self, page=None, language=None, **kwargs):
        from shop.search.views import SearchView
        from {{ cookiecutter.app_name }}.serializers import ProductSearchSerializer

        return [
            url(r'^', SearchView.as_view(
                serializer_class=ProductSearchSerializer,
# -*- 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'
    )),
]
Example #8
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 shop.views.catalog import ProductListView, ProductRetrieveView, AddToCartView

from myshop.serializers import ProductSummarySerializer, ProductDetailSerializer

urlpatterns = [
    url(r'^$', ProductListView.as_view(
        serializer_class=ProductSummarySerializer,
        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'
    )),
]
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, )),
)
        from {{ cookiecutter.app_name }}.filters import ManufacturerFilterSet
        from {{ cookiecutter.app_name }}.serializers import AddSmartPhoneToCartSerializer

        ProductListView = type('ProductSearchListView', (AddFilterContextMixin, {% if cookiecutter.use_elasticsearch == 'y' %}ProductSearchViewMixin, {% endif %}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,
            )),
        ]
{%- else %}{% set use_lookup_field = (cookiecutter.products_model == 'commodity' and cookiecutter.use_i18n == 'y') %}
        from {{ cookiecutter.app_name }}.serializers import ProductDetailSerializer
    {% if cookiecutter.use_elasticsearch == 'y' %}
        ProductListView = type('ProductSearchListView', (ProductSearchViewMixin, ProductListView), {})
    {%- endif %}
        return [
            url(r'^(?P<slug>[\w-]+)/add-to-cart', AddToCartView.as_view({% if use_lookup_field %}lookup_field='translations__slug'{% endif %})),
            url(r'^(?P<slug>[\w-]+)', ProductRetrieveView.as_view(
                serializer_class=ProductDetailSerializer,
    {%- if use_lookup_field %}
                lookup_field='translations__slug'
    {%- endif %}
            )),
Example #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'
    )),
]
Example #12
0
# -*- 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, ProductListView, ProductRetrieveView

from myshop.serializers import ProductSummarySerializer, ProductDetailSerializer

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