Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactored template arrangement, only one template include loader is …

…used and plugins describe a template in their context
  • Loading branch information...
commit 3036bb824e0e68430f291885949cf189d0eed919 1 parent 1d7c907
Zenobius Jiricek authored
View
18 cmsplugin_configurableproduct/cms_plugins.py
@@ -12,6 +12,7 @@
from .models import (
CProductTypesPlugin,
CProductsPlugin,
+ TEMPLATE_BASE_PATH,
PRODUCT_TYPE_TEMPLATE_PATH,
PRODUCT_LIST_TEMPLATE_PATH,
)
@@ -19,27 +20,36 @@
class ProductCategories(CMSPluginBase):
model = CProductTypesPlugin
name = _("List of Product Types")
- render_template = os.path.join(PRODUCT_TYPE_TEMPLATE_PATH, "base.html")
+ render_template = os.path.join(TEMPLATE_BASE_PATH, "base.html")
+ default_template = os.path.join(PRODUCT_TYPE_TEMPLATE_PATH, "default.html")
def render(self, context, instance, placeholder):
objects = Product.objects.filter(active=True)
used_types = objects.values("type").distinct()
types = ProductType.objects.filter(pk__in = used_types)
- context.update({'Types': types, })
+
+ context.update({
+ 'Types': types,
+ 'Template' : instance.template if instance.template else self.default_template
+ })
+
return context
+
plugin_pool.register_plugin(ProductCategories)
class CategoryProducts(CMSPluginBase):
model = CProductsPlugin
name = _("List of Products")
- render_template = os.path.join(PRODUCT_LIST_TEMPLATE_PATH, "base.html")
+ render_template = os.path.join(TEMPLATE_BASE_PATH, "base.html")
+ default_template = os.path.join(PRODUCT_TYPE_TEMPLATE_PATH, "default.html")
def render(self, context, instance, placeholder):
products = Product.objects.filter(type__pk__in = instance.categories.all())
context.update({
- "Products": products
+ "Products": products,
+ 'Template' : instance.template if instance.template else self.default_template
})
return context
View
8 cmsplugin_configurableproduct/models.py
@@ -12,6 +12,11 @@
from .lib.choices import DynamicChoice
+TEMPLATE_BASE_PATH = "cmsplugin_configurable_product"
+PRODUCT_TYPE_TEMPLATE_PATH = os.path.join(TEMPLATE_BASE_PATH, "product-types")
+PRODUCT_LIST_TEMPLATE_PATH = os.path.join(TEMPLATE_BASE_PATH, "product-list")
+
+
class DynamicTemplateChoices(DynamicChoice):
path = None
exclude = None
@@ -60,8 +65,7 @@ def walkdir(self, path=None):
return output
-PRODUCT_TYPE_TEMPLATE_PATH = os.path.join("cmsplugin_configurable_product", "product-types")
-PRODUCT_LIST_TEMPLATE_PATH = os.path.join("cmsplugin_configurable_product", "product-list")
+
class CProductTypesPlugin(CMSPlugin):
""" Stores options for cmsplugin that shows lists of ProductTypes
View
1  cmsplugin_configurableproduct/templates/cmsplugin_configurable_product/base.html
@@ -0,0 +1 @@
+{% include Template %}
View
1  ...lugin_configurableproduct/templates/cmsplugin_configurable_product/product-list/base.html
@@ -1 +0,0 @@
-{% include plugin.instance.template %}
View
6 ...in_configurableproduct/templates/cmsplugin_configurable_product/product-list/default.html
@@ -0,0 +1,6 @@
+{% for Product in Products %}
+<div id="product-{{ Product.id }}"
+ data-product-type="{{ Product.type|slugify }}">
+ {{ Product }}
+</div>
+{% endfor %}
View
1  ...ugin_configurableproduct/templates/cmsplugin_configurable_product/product-types/base.html
@@ -1 +0,0 @@
-{% include plugin.instance.template %}
View
6 ...n_configurableproduct/templates/cmsplugin_configurable_product/product-types/default.html
@@ -0,0 +1,6 @@
+{% for Type in Types %}
+<div id="product-{{ Type.id }}"
+ data-product-type="{{ Type.name|slugify }}">
+ {{ Product }}
+</div>
+{% endfor %}
Please sign in to comment.
Something went wrong with that request. Please try again.