dynamicweb/datacenterlight/cms_plugins.py

200 lines
6.4 KiB
Python
Raw Normal View History

2018-02-27 22:39:19 +00:00
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from .cms_models import (
2018-03-01 20:35:42 +00:00
DCLBannerItemPluginModel, DCLBannerListPluginModel, DCLContactPluginModel,
DCLFooterPluginModel, DCLLinkPluginModel, DCLNavbarDropdownPluginModel,
DCLSectionIconPluginModel, DCLSectionImagePluginModel,
2018-03-21 19:22:06 +00:00
DCLSectionPluginModel, DCLNavbarPluginModel,
2018-04-15 21:24:15 +00:00
DCLSectionPromoPluginModel, DCLCustomPricingModel
2018-02-27 22:39:19 +00:00
)
from .models import VMTemplate, VMPricing
2018-02-27 22:39:19 +00:00
@plugin_pool.register_plugin
2018-03-01 20:35:42 +00:00
class DCLSectionPlugin(CMSPluginBase):
2018-02-27 22:39:19 +00:00
module = "Datacenterlight"
2018-03-01 20:35:42 +00:00
name = "DCL Section Plugin"
2018-02-27 22:39:19 +00:00
model = DCLSectionPluginModel
2018-03-01 20:35:42 +00:00
render_template = "datacenterlight/cms/section.html"
2018-02-27 22:39:19 +00:00
cache = False
2018-03-01 20:35:42 +00:00
allow_children = True
2018-03-21 19:22:06 +00:00
child_classes = [
'DCLSectionIconPlugin', 'DCLSectionImagePlugin',
'DCLSectionPromoPlugin', 'UngleichHTMLPlugin'
]
def render(self, context, instance, placeholder):
context = super(DCLSectionPlugin, self).render(
context, instance, placeholder
)
context['children_to_side'] = []
context['children_to_content'] = []
2018-03-21 19:22:06 +00:00
if instance.child_plugin_instances is not None:
2018-03-22 19:57:51 +00:00
right_children = [
'DCLSectionImagePluginModel',
'DCLSectionIconPluginModel'
]
2018-03-21 19:22:06 +00:00
for child in instance.child_plugin_instances:
2018-03-22 19:57:51 +00:00
if child.__class__.__name__ in right_children:
context['children_to_side'].append(child)
2018-03-21 19:22:06 +00:00
else:
context['children_to_content'].append(child)
2018-03-21 19:22:06 +00:00
return context
2018-02-27 22:39:19 +00:00
@plugin_pool.register_plugin
2018-03-01 20:35:42 +00:00
class DCLSectionIconPlugin(CMSPluginBase):
2018-02-27 22:39:19 +00:00
module = "Datacenterlight"
2018-03-01 20:35:42 +00:00
name = "DCL Section Icon Plugin"
model = DCLSectionIconPluginModel
render_template = "datacenterlight/cms/section_icon.html"
cache = False
require_parent = True
@plugin_pool.register_plugin
class DCLSectionImagePlugin(CMSPluginBase):
module = "Datacenterlight"
name = "DCL Section Image Plugin"
model = DCLSectionImagePluginModel
render_template = "datacenterlight/cms/section_image.html"
cache = False
require_parent = True
2018-03-21 19:22:06 +00:00
@plugin_pool.register_plugin
class DCLSectionPromoPlugin(CMSPluginBase):
module = "Datacenterlight"
name = "DCL Section Promo Plugin"
model = DCLSectionPromoPluginModel
render_template = "datacenterlight/cms/section_promo.html"
cache = False
2018-03-01 20:35:42 +00:00
@plugin_pool.register_plugin
class DCLCalculatorPlugin(CMSPluginBase):
module = "Datacenterlight"
name = "DCL Calculator Section Plugin"
model = DCLSectionPluginModel
2018-03-01 20:35:42 +00:00
render_template = "datacenterlight/cms/calculator.html"
2018-02-27 22:39:19 +00:00
cache = False
allow_children = True
child_classes = [
2018-04-15 21:24:15 +00:00
'DCLSectionPromoPlugin', 'UngleichHTMLPlugin', 'DCLCustomPricingPlugin'
]
2018-02-27 22:39:19 +00:00
def render(self, context, instance, placeholder):
context = super(DCLCalculatorPlugin, self).render(
context, instance, placeholder
)
context['templates'] = VMTemplate.objects.all()
context['children_to_side'] = []
context['children_to_content'] = []
pricing_plugin_model = None
if instance.child_plugin_instances:
for child in instance.child_plugin_instances:
if child.__class__.__name__ == 'DCLCustomPricingModel':
# The second clause is just to make sure we pick up the
# most recent CustomPricing, if more than one is present
if (pricing_plugin_model is None or child.pricing_id >
pricing_plugin_model.model.pricing_id):
pricing_plugin_model = child
if pricing_plugin_model:
context['vm_pricing'] = VMPricing.get_vm_pricing_by_name(
name=pricing_plugin_model.pricing.name
)
else:
context['vm_pricing'] = VMPricing.get_default_pricing()
if instance.child_plugin_instances is not None:
context['children_to_content'].extend(
instance.child_plugin_instances
)
return context
2018-02-27 22:39:19 +00:00
2018-04-15 21:24:15 +00:00
@plugin_pool.register_plugin
class DCLCustomPricingPlugin(CMSPluginBase):
module = "Datacenterlight"
name = "DCL Custom Pricing Plugin"
model = DCLCustomPricingModel
render_plugin = False
2018-02-27 22:39:19 +00:00
@plugin_pool.register_plugin
2018-03-01 20:35:42 +00:00
class DCLBannerListPlugin(CMSPluginBase):
2018-02-27 22:39:19 +00:00
module = "Datacenterlight"
2018-03-01 20:35:42 +00:00
name = "DCL Banner List Plugin"
model = DCLBannerListPluginModel
render_template = "datacenterlight/cms/banner_list.html"
2018-02-27 22:39:19 +00:00
cache = False
allow_children = True
2018-03-01 20:35:42 +00:00
child_classes = ['DCLBannerItemPlugin']
2018-02-27 22:39:19 +00:00
@plugin_pool.register_plugin
2018-03-01 20:35:42 +00:00
class DCLBannerItemPlugin(CMSPluginBase):
2018-02-27 22:39:19 +00:00
module = "Datacenterlight"
2018-03-01 20:35:42 +00:00
name = "DCL Banner Item Plugin"
model = DCLBannerItemPluginModel
render_template = "datacenterlight/cms/banner_item.html"
2018-02-27 22:39:19 +00:00
cache = False
require_parent = True
2018-03-01 20:35:42 +00:00
parent_classes = ['DCLBannerListPlugin']
@plugin_pool.register_plugin
class DCLNavbarPlugin(CMSPluginBase):
module = "Datacenterlight"
name = "DCL Navbar Plugin"
2018-03-16 09:59:24 +00:00
model = DCLNavbarPluginModel
2018-03-01 20:35:42 +00:00
render_template = "datacenterlight/cms/navbar.html"
cache = False
allow_children = True
child_classes = ['DCLLinkPlugin', 'DCLNavbarDropdownPlugin']
2018-02-27 22:39:19 +00:00
@plugin_pool.register_plugin
class DCLNavbarDropdownPlugin(CMSPluginBase):
module = "Datacenterlight"
2018-03-01 20:35:42 +00:00
name = "DCL Navbar Dropdown Plugin"
2018-02-27 22:39:19 +00:00
model = DCLNavbarDropdownPluginModel
render_template = "datacenterlight/cms/navbar_dropdown.html"
cache = False
allow_children = True
child_classes = ['DCLLinkPlugin']
require_parent = True
parent_classes = ['DCLNavbarPlugin']
2018-03-01 20:35:42 +00:00
@plugin_pool.register_plugin
class DCLLinkPlugin(CMSPluginBase):
module = "Datacenterlight"
name = "DCL Link Plugin"
model = DCLLinkPluginModel
render_template = "datacenterlight/cms/link.html"
cache = False
require_parent = True
2018-02-27 22:39:19 +00:00
@plugin_pool.register_plugin
class DCLContactPlugin(CMSPluginBase):
module = "Datacenterlight"
2018-03-01 20:35:42 +00:00
name = "DCL Contact Plugin"
2018-02-27 22:39:19 +00:00
model = DCLContactPluginModel
render_template = "datacenterlight/cms/contact.html"
cache = False
@plugin_pool.register_plugin
class DCLFooterPlugin(CMSPluginBase):
module = "Datacenterlight"
2018-03-01 20:35:42 +00:00
name = "DCL Footer Plugin"
2018-02-27 22:39:19 +00:00
model = DCLFooterPluginModel
render_template = "datacenterlight/cms/footer.html"
cache = False
allow_children = True
child_classes = ['DCLLinkPlugin']