Add generic header plugin & model

This commit is contained in:
PCoder 2019-11-27 12:54:58 +05:30
parent 3d28b17c71
commit 249769f732
2 changed files with 44 additions and 1 deletions

View file

@ -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"
)

View file

@ -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