add calculator placeholder to cms_integration
This commit is contained in:
parent
67a6c8f2c2
commit
3bf064a017
13 changed files with 195 additions and 74 deletions
|
|
@ -1,3 +1,4 @@
|
|||
from cms.models.pluginmodel import CMSPlugin
|
||||
from cms.plugin_base import CMSPluginBase
|
||||
from cms.plugin_pool import plugin_pool
|
||||
|
||||
|
|
@ -6,7 +7,7 @@ from .cms_models import (
|
|||
DCLFooterPluginModel, DCLLinkPluginModel, DCLNavbarDropdownPluginModel,
|
||||
DCLSectionIconPluginModel, DCLSectionImagePluginModel,
|
||||
DCLSectionPluginModel, DCLNavbarPluginModel,
|
||||
DCLSectionPromoPluginModel, DCLCustomPricingModel
|
||||
DCLSectionPromoPluginModel, DCLCalculatorPluginModel
|
||||
)
|
||||
from .models import VMTemplate, VMPricing
|
||||
|
||||
|
|
@ -21,7 +22,7 @@ class DCLSectionPlugin(CMSPluginBase):
|
|||
allow_children = True
|
||||
child_classes = [
|
||||
'DCLSectionIconPlugin', 'DCLSectionImagePlugin',
|
||||
'DCLSectionPromoPlugin', 'UngleichHTMLPlugin'
|
||||
'DCLSectionPromoPlugin', 'UngleichHTMLPlugin', 'DCLCalculatorPlugin'
|
||||
]
|
||||
|
||||
def render(self, context, instance, placeholder):
|
||||
|
|
@ -30,14 +31,18 @@ class DCLSectionPlugin(CMSPluginBase):
|
|||
)
|
||||
context['children_to_side'] = []
|
||||
context['children_to_content'] = []
|
||||
context['children_calculator'] = []
|
||||
if instance.child_plugin_instances is not None:
|
||||
right_children = [
|
||||
'DCLSectionImagePluginModel',
|
||||
'DCLSectionIconPluginModel'
|
||||
'DCLSectionIconPluginModel',
|
||||
]
|
||||
for child in instance.child_plugin_instances:
|
||||
print(child.__dict__)
|
||||
if child.__class__.__name__ in right_children:
|
||||
context['children_to_side'].append(child)
|
||||
elif child.__class__.__name__ == 'CMSPlugin':
|
||||
context['children_calculator'].append(child)
|
||||
else:
|
||||
context['children_to_content'].append(child)
|
||||
return context
|
||||
|
|
@ -75,50 +80,42 @@ class DCLSectionPromoPlugin(CMSPluginBase):
|
|||
@plugin_pool.register_plugin
|
||||
class DCLCalculatorPlugin(CMSPluginBase):
|
||||
module = "Datacenterlight"
|
||||
name = "DCL Calculator Section Plugin"
|
||||
model = DCLSectionPluginModel
|
||||
name = "DCL Calculator Plugin"
|
||||
model = DCLCalculatorPluginModel
|
||||
render_template = "datacenterlight/cms/calculator.html"
|
||||
cache = False
|
||||
allow_children = True
|
||||
child_classes = [
|
||||
'DCLSectionPromoPlugin', 'UngleichHTMLPlugin', 'DCLCustomPricingPlugin'
|
||||
]
|
||||
require_parent = True
|
||||
|
||||
def render(self, context, instance, placeholder):
|
||||
context = super(DCLCalculatorPlugin, self).render(
|
||||
context, instance, placeholder
|
||||
)
|
||||
context['templates'] = VMTemplate.objects.all()
|
||||
context['children_to_content'] = []
|
||||
pricing_plugin_model = None
|
||||
if instance.child_plugin_instances is not None:
|
||||
context['children_to_content'].extend(
|
||||
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()
|
||||
# pricing_plugin_model = None
|
||||
# if instance.child_plugin_instances is not None:
|
||||
# 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()
|
||||
return context
|
||||
|
||||
|
||||
@plugin_pool.register_plugin
|
||||
class DCLCustomPricingPlugin(CMSPluginBase):
|
||||
module = "Datacenterlight"
|
||||
name = "DCL Custom Pricing Plugin"
|
||||
model = DCLCustomPricingModel
|
||||
render_plugin = False
|
||||
# @plugin_pool.register_plugin
|
||||
# class DCLCustomPricingPlugin(CMSPluginBase):
|
||||
# module = "Datacenterlight"
|
||||
# name = "DCL Custom Pricing Plugin"
|
||||
# model = DCLCustomPricingModel
|
||||
# render_plugin = False
|
||||
|
||||
|
||||
@plugin_pool.register_plugin
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue