From 0935877a4fc65efaea058a1f6e4ff633a3a0a1a0 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 19 Oct 2017 13:45:28 +0200 Subject: [PATCH] Add get_section_id --- ungleich_page/cms_plugins.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ungleich_page/cms_plugins.py b/ungleich_page/cms_plugins.py index 19afce96..388e6049 100644 --- a/ungleich_page/cms_plugins.py +++ b/ungleich_page/cms_plugins.py @@ -7,6 +7,22 @@ from .models import ( ) +def get_section_id(plugin_instance, default): + """ + A helper function to get the section id from a given menu text + :param plugin_instance: + :param default: The default section id to return in case a section id + is not found + :return: The section id for the plugin_instance + """ + section_id = default + if hasattr(plugin_instance, 'menu_text'): + menu_words = plugin_instance.menu_text.split() + if len(menu_words) > 0: + section_id = menu_words[0] + return section_id + + @plugin_pool.register_plugin class SectionWithImagePlugin(CMSPluginBase): model = SectionWithImage @@ -35,6 +51,14 @@ class SectionTextParagraphDCL(CMSPluginBase): render_template = "ungleich_page/glasfaser/section_text_dcl.html" cache = False + def render(self, context, instance, placeholder): + context = super(SectionTextParagraphDCL, self).render( + context, instance, placeholder + ) + context['instance'] = instance + context['section_id'] = get_section_id(instance, 'your') + return context + @plugin_pool.register_plugin class SectionTextParagraphGlasfaser(CMSPluginBase): @@ -42,6 +66,14 @@ class SectionTextParagraphGlasfaser(CMSPluginBase): render_template = "ungleich_page/glasfaser/section_text_glasfaser.html" cache = False + def render(self, context, instance, placeholder): + context = super(SectionTextParagraphGlasfaser, self).render( + context, instance, placeholder + ) + context['instance'] = instance + context['section_id'] = get_section_id(instance, 'our') + return context + @plugin_pool.register_plugin class GlasfaserServicesPlugin(CMSPluginBase):