# Path: cmsplugin_shop/utils.py
# def get_view(name):
#     view = import_string(getattr(
#         settings.settings,
#         'CMSPLUGIN_SHOP_{}_VIEW'.format(name.upper()),
#         'cmsplugin_shop.views.{}'.format(name),
#     ))
#     return hasattr(view, 'as_view') and view.as_view() or view
# 
# def get_form(name):
#     return import_string(getattr(settings.settings,
#         'CMSPLUGIN_SHOP_{}_FORM'.format(name.upper()),
#         'cmsplugin_shop.forms.{}Form'.format(name),
#     ))


import cStringIO
from cms.views import details as cms_page
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse
from django.forms import ModelForm
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, get_object_or_404
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.views.generic import (
    CreateView, DetailView, FormView, ListView,
    TemplateView, UpdateView, View,
)
from formtools.wizard.views import SessionWizardView
from os.path import basename
from xhtml2pdf import pisa
from . import models, settings
from .utils import get_view, get_form
            )
            item.quantity += form.instance.quantity
            item.save()
        except form.instance.__class__.DoesNotExist:
            form.instance.tax_rate = form.instance.product.tax_rate
            form.instance.price = form.instance.package \
                                and form.instance.package.price \
                                 or form.instance.product.price
            form.instance.save()
        messages.add_message(self.request, messages.INFO,
            mark_safe(_('Product has been added to <a href="{}">shopping cart</a>').format(reverse('Cart:cart')))
        )
        return super(ProductView, self).form_valid(form)

    def get_success_url(self):
        if 'add-and-cart' in self.request.POST:
            return reverse('Cart:cart')
        else:
            return self.kwargs['product'].get_absolute_url()



# catalog views
root        = TemplateView.as_view(template_name='cmsplugin_shop/root.html')
category    = TemplateView.as_view(template_name='cmsplugin_shop/category.html')
product     = ProductView.as_view(template_name='cmsplugin_shop/product.html')



class CatalogView(View):

# Path: cmsplugin_shop/utils.py
# def get_view(name):
#     view = import_string(getattr(
#         settings.settings,
#         'CMSPLUGIN_SHOP_{}_VIEW'.format(name.upper()),
#         'cmsplugin_shop.views.{}'.format(name),
#     ))
#     return hasattr(view, 'as_view') and view.as_view() or view
# 
# def get_form(name):
#     return import_string(getattr(settings.settings,
#         'CMSPLUGIN_SHOP_{}_FORM'.format(name.upper()),
#         'cmsplugin_shop.forms.{}Form'.format(name),
#     ))


# Path: cmsplugin_shop/views.py
import cStringIO
from cms.views import details as cms_page
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse
from django.forms import ModelForm
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, get_object_or_404
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.views.generic import (
    CreateView, DetailView, FormView, ListView,
    TemplateView, UpdateView, View,
)
from formtools.wizard.views import SessionWizardView
from os.path import basename
from xhtml2pdf import pisa
from . import models, settings
from .utils import get_view, get_form

            )
            item.quantity += form.instance.quantity
            item.save()
        except form.instance.__class__.DoesNotExist:
            form.instance.tax_rate = form.instance.product.tax_rate
            form.instance.price = form.instance.package \
                                and form.instance.package.price \
                                 or form.instance.product.price
            form.instance.save()
        messages.add_message(self.request, messages.INFO,
            mark_safe(_('Product has been added to <a href="{}">shopping cart</a>').format(reverse('Cart:cart')))
        )
        return super(ProductView, self).form_valid(form)

    def get_success_url(self):
        if 'add-and-cart' in self.request.POST:
            return reverse('Cart:cart')
        else:
            return self.kwargs['product'].get_absolute_url()



# catalog views
root        = TemplateView.as_view(template_name='cmsplugin_shop/root.html')
category    = TemplateView.as_view(template_name='cmsplugin_shop/category.html')
product     = ProductView.as_view(template_name='cmsplugin_shop/product.html')



class CatalogView(View):

    root_view       = staticmethod(get_view('root'))