From 896984ef1f0f8105760fdcba86e1d515d3757c2c Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 16 Apr 2018 00:29:23 +0200 Subject: [PATCH] Set vm_pricing context from plugins value --- datacenterlight/cms_plugins.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/datacenterlight/cms_plugins.py b/datacenterlight/cms_plugins.py index d504956a..2ad07249 100644 --- a/datacenterlight/cms_plugins.py +++ b/datacenterlight/cms_plugins.py @@ -91,7 +91,21 @@ class DCLCalculatorPlugin(CMSPluginBase): context['templates'] = VMTemplate.objects.all() context['children_to_side'] = [] context['children_to_content'] = [] - context['vm_pricing'] = VMPricing.get_default_pricing() + pricing_plugin_model = 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() if instance.child_plugin_instances is not None: context['children_to_content'].extend(