Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 95caa9027a
Fetching contributors…

Cannot retrieve contributors at this time

89 lines (67 sloc) 2.371 kB
import os
from django.utils.translation import ugettext_lazy as _
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from cms.models.pluginmodel import CMSPlugin
from configurableproduct.models import CProduct as Product
from configurableproduct.models.producttypes import ProductType
from .lib.choices import (
DynamicTemplateChoices,
DynamicChoice,
)
from .models import (
CProductTypesPlugin,
CProductsPlugin,
ApplicationSettings,
)
from .forms import (
CProductTypesAdminForm,
CProductsAdminForm,
)
class ProductCategories(CMSPluginBase):
model = CProductTypesPlugin
name = _("List of Product Types")
render_template = os.path.join(ApplicationSettings.TEMPLATE_BASE_PATH, "base.html")
admin_preview = False
form = CProductTypesAdminForm
filter_horizontal = ('categories', )
def render(self, context, instance, placeholder):
types = ProductType.objects.all()
chosen_categories = instance.categories.all()
if chosen_categories :
types = chosen_categories
if instance.hide_empty_categories :
objects = Product.objects.filter(active=True)
used_types = objects.values("type").distinct()
types = types.filter(pk__in = used_types)
context.update({
'Types': types,
})
return context
plugin_pool.register_plugin(ProductCategories)
class CategoryProducts(CMSPluginBase):
model = CProductsPlugin
name = _("List of Products")
render_template = os.path.join(ApplicationSettings.TEMPLATE_BASE_PATH, "base.html")
admin_preview = False
form = CProductsAdminForm
filter_horizontal = ('categories', )
fieldsets = (
('Display Template',
{'fields': [ ('template', ),
]}),
('Show Products of Type...',
{'fields': [ ('hide_empty_categories','categories', ),
]}),
('Filtering', {
'classes': ('collapse',),
'fields': ['filter_action', 'filter_product_attributes']
}),
)
def render(self, context, instance, placeholder):
products = Product.objects.filter(type__pk__in = instance.categories.all())
context.update({
"Products": products,
})
return context
plugin_pool.register_plugin(CategoryProducts)
Jump to Line
Something went wrong with that request. Please try again.