diff --git a/datacenterlight/cms_models.py b/datacenterlight/cms_models.py index 2d1a98b5..99940d03 100644 --- a/datacenterlight/cms_models.py +++ b/datacenterlight/cms_models.py @@ -13,6 +13,7 @@ from filer.fields.file import FilerFileField from filer.fields.image import FilerImageField from datacenterlight.models import VMPricing, VMTemplate +from hosting.models import GenericProduct class CMSIntegration(models.Model): @@ -362,3 +363,22 @@ class DCLCalculatorPluginModel(CMSPlugin): " default when the calculator loads" ) enable_512mb_ram = models.BooleanField(default=False) + + +class GenericProductHeaderPluginModel(CMSPlugin): + generic_product = models.ForeignKey( + GenericProduct, + related_name="dcl_generic_product_header_plugin", + help_text='Choose or create a generic product that you want to link ' + 'with this header', + null=True, + blank=True + ) + header_text = models.TextField( + help_text="Give a header text" + ) + header_background_color = models.CharField(default="3c4e68", max_length=10) + buy_button_text = models.TextField( + default="Buy now", + help_text="Input the text to be shown on the buy button" + ) \ No newline at end of file diff --git a/datacenterlight/cms_plugins.py b/datacenterlight/cms_plugins.py index c3ec974f..7d503e9e 100644 --- a/datacenterlight/cms_plugins.py +++ b/datacenterlight/cms_plugins.py @@ -1,3 +1,5 @@ +from django.core.urlresolvers import reverse + from cms.plugin_base import CMSPluginBase from cms.plugin_pool import plugin_pool @@ -6,7 +8,8 @@ from .cms_models import ( DCLFooterPluginModel, DCLLinkPluginModel, DCLNavbarDropdownPluginModel, DCLSectionIconPluginModel, DCLSectionImagePluginModel, DCLSectionPluginModel, DCLNavbarPluginModel, - DCLSectionPromoPluginModel, DCLCalculatorPluginModel + DCLSectionPromoPluginModel, DCLCalculatorPluginModel, + GenericProductHeaderPluginModel ) from .models import VMTemplate from datacenterlight.utils import clear_all_session_vars @@ -178,3 +181,23 @@ class DCLFooterPlugin(CMSPluginBase): cache = False allow_children = True child_classes = ['DCLLinkPlugin'] + + +@plugin_pool.register_plugin +class GenericProductHeaderPlugin(CMSPluginBase): + module = "Datacenterlight" + name = "Generic Product Header Plugin" + model = GenericProductHeaderPluginModel + render_template = "datacenterlight/cms/generic_product_header.html" + cache = False + + def render(self, context, instance, placeholder): + product_url = None + if instance.generic_product: + product_url = reverse( + 'show_product', + kwargs={'product_slug': instance.generic_product.product_slug} + ) + context["product_url"] = product_url + context["instance"] = instance + return context \ No newline at end of file