From bbfb37dd8fc97ba9dd2674f066dd92ff311b2257 Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Thu, 22 Mar 2018 00:52:06 +0530 Subject: [PATCH] new plugins section --- datacenterlight/cms_models.py | 35 +++++++++++++++++++ datacenterlight/cms_plugins.py | 31 ++++++++++++++-- .../static/datacenterlight/js/main.js | 12 ++++--- .../datacenterlight/cms/calculator.html | 17 ++------- .../cms/includes/_section_split_content.html | 21 +++++++++++ .../datacenterlight/cms/section.html | 34 ++++-------------- .../datacenterlight/cms/section_promo.html | 11 ++++++ datacenterlight/templatetags/custom_tags.py | 7 +++- 8 files changed, 118 insertions(+), 50 deletions(-) create mode 100644 datacenterlight/templates/datacenterlight/cms/includes/_section_split_content.html create mode 100644 datacenterlight/templates/datacenterlight/cms/section_promo.html diff --git a/datacenterlight/cms_models.py b/datacenterlight/cms_models.py index df54589e..214a2e90 100644 --- a/datacenterlight/cms_models.py +++ b/datacenterlight/cms_models.py @@ -200,3 +200,38 @@ class DCLSectionImagePluginModel(CMSPlugin): max_length=100, null=True, blank=True, help_text='Optional caption for the image.' ) + + +class DCLSectionPromoPluginModel(CMSPlugin): + background_image = FilerImageField( + on_delete=models.CASCADE, null=True, blank=True, + help_text=('Optional background image for the Promo Section'), + related_name="dcl_section_promo_promo", + ) + heading = models.CharField( + blank=True, null=True, max_length=100, + help_text='An optional heading for the Promo Section', + ) + subheading = models.CharField( + blank=True, null=True, max_length=200, + help_text='An optional subheading for the Promo Section', + ) + content = HTMLField() + html_id = models.SlugField( + blank=True, null=True, + help_text=( + 'An optional html id for the Section. Required to set as target ' + 'of a link on page' + ) + ) + plain_heading = models.BooleanField( + default=False, + help_text='Select to keep the heading style simpler.' + ) + center_on_mobile = models.BooleanField( + default=False, + help_text='Select to center align content on small screens.' + ) + + def __str__(self): + return '#' + self.html_id if self.html_id else str(self.pk) diff --git a/datacenterlight/cms_plugins.py b/datacenterlight/cms_plugins.py index 60992889..42e8719f 100644 --- a/datacenterlight/cms_plugins.py +++ b/datacenterlight/cms_plugins.py @@ -5,7 +5,8 @@ from .cms_models import ( DCLBannerItemPluginModel, DCLBannerListPluginModel, DCLContactPluginModel, DCLFooterPluginModel, DCLLinkPluginModel, DCLNavbarDropdownPluginModel, DCLSectionIconPluginModel, DCLSectionImagePluginModel, - DCLSectionPluginModel, DCLNavbarPluginModel + DCLSectionPluginModel, DCLNavbarPluginModel, + DCLSectionPromoPluginModel ) from .models import VMTemplate @@ -18,7 +19,24 @@ class DCLSectionPlugin(CMSPluginBase): render_template = "datacenterlight/cms/section.html" cache = False allow_children = True - child_classes = ['DCLSectionIconPlugin', 'DCLSectionImagePlugin'] + child_classes = [ + 'DCLSectionIconPlugin', 'DCLSectionImagePlugin', + 'DCLSectionPromoPlugin', 'UngleichHTMLPlugin' + ] + + def render(self, context, instance, placeholder): + context = super(DCLSectionPlugin, self).render( + context, instance, placeholder + ) + context['children_to_right'] = [] + context['children_to_left'] = [] + if instance.child_plugin_instances is not None: + for child in instance.child_plugin_instances: + if child.__class__.__name__ == 'DCLSectionImagePluginModel': + context['children_to_right'].append(child) + else: + context['children_to_left'].append(child) + return context @plugin_pool.register_plugin @@ -41,6 +59,15 @@ class DCLSectionImagePlugin(CMSPluginBase): require_parent = True +@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 + + @plugin_pool.register_plugin class DCLCalculatorPlugin(CMSPluginBase): module = "Datacenterlight" diff --git a/datacenterlight/static/datacenterlight/js/main.js b/datacenterlight/static/datacenterlight/js/main.js index 10412824..5e919045 100644 --- a/datacenterlight/static/datacenterlight/js/main.js +++ b/datacenterlight/static/datacenterlight/js/main.js @@ -107,10 +107,14 @@ var href = $(this).attr('href'); $('.navbar-collapse').removeClass('in'); $('.navbar-collapse').addClass('collapsing'); - if ($(href).length) { - $('html, body').animate({ - scrollTop: $(href).offset().top - 50 - }, 1000); + if (href[0] === "#") { + if ($(href).length) { + $('html, body').animate({ + scrollTop: $(href).offset().top - 50 + }, 1000); + } + } else if (href) { + window.location = href; } }); } diff --git a/datacenterlight/templates/datacenterlight/cms/calculator.html b/datacenterlight/templates/datacenterlight/cms/calculator.html index 5ea97e84..27d1f89c 100644 --- a/datacenterlight/templates/datacenterlight/cms/calculator.html +++ b/datacenterlight/templates/datacenterlight/cms/calculator.html @@ -1,21 +1,8 @@
-
-
- {% if instance.heading %} -
-

{{ instance.heading }}

-
- {% endif %} - {% if instance.content %} -
-
- {{ instance.content }} -
-
- {% endif %} -
+
+ {% include "datacenterlight/cms/includes/_section_split_content.html" %}
diff --git a/datacenterlight/templates/datacenterlight/cms/includes/_section_split_content.html b/datacenterlight/templates/datacenterlight/cms/includes/_section_split_content.html new file mode 100644 index 00000000..38db14d5 --- /dev/null +++ b/datacenterlight/templates/datacenterlight/cms/includes/_section_split_content.html @@ -0,0 +1,21 @@ +{% load cms_tags %} + +{% if instance.heading %} +
+

{{ instance.heading }}

+
+{% endif %} +{% if instance.content %} +
+
+ {{ instance.content }} +
+
+{% endif %} +{% if children_to_left|length %} +
+ {% for plugin in children_to_left %} + {% render_plugin plugin %} + {% endfor %} +
+{% endif %} \ No newline at end of file diff --git a/datacenterlight/templates/datacenterlight/cms/section.html b/datacenterlight/templates/datacenterlight/cms/section.html index bdef3196..7500ceb3 100644 --- a/datacenterlight/templates/datacenterlight/cms/section.html +++ b/datacenterlight/templates/datacenterlight/cms/section.html @@ -1,26 +1,15 @@ {% load cms_tags %} -
+
- {% if instance.child_plugin_instances|length %} + {% if children_to_right|length %}
- {% if instance.heading %} -
-

{{ instance.heading }}

-
- {% endif %} - {% if instance.content %} -
-
- {{ instance.content }} -
-
- {% endif %} + {% include "datacenterlight/cms/includes/_section_split_content.html" %}
- {% for plugin in instance.child_plugin_instances %} + {% for plugin in children_to_right %} {% render_plugin plugin %} {% endfor %}
@@ -28,19 +17,8 @@
{% else %}
- {% if instance.heading %} -
-

{{ instance.heading }}

-
- {% endif %} - {% if instance.content %} -
-
- {{ instance.content }} -
-
- {% endif %} + {% include "datacenterlight/cms/includes/_section_split_content.html" %}
{% endif %}
-
\ No newline at end of file +
\ No newline at end of file diff --git a/datacenterlight/templates/datacenterlight/cms/section_promo.html b/datacenterlight/templates/datacenterlight/cms/section_promo.html new file mode 100644 index 00000000..46a6b67c --- /dev/null +++ b/datacenterlight/templates/datacenterlight/cms/section_promo.html @@ -0,0 +1,11 @@ +
+ {% if instance.heading %} +

{{instance.heading}}

+ {% endif %} + {% if instance.subheading %} +

{{instance.subheading}}

+ {% endif %} + {% if instance.content %} +

{{instance.content}}

+ {% endif %} +
\ No newline at end of file diff --git a/datacenterlight/templatetags/custom_tags.py b/datacenterlight/templatetags/custom_tags.py index 908b1f89..2ff32bf1 100644 --- a/datacenterlight/templatetags/custom_tags.py +++ b/datacenterlight/templatetags/custom_tags.py @@ -41,4 +41,9 @@ def multiply(value, arg): :param arg: :return: """ - return value*arg + return value * arg + + +@register.filter('instance_class') +def instance_class(obj): + return obj.__class__.__name__