From c147b48af7c00da45c132be1d43affd4c7877eec Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 19 Oct 2017 13:39:56 +0200 Subject: [PATCH] Add first version of cms_menus.py --- ungleich_page/cms_menus.py | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 ungleich_page/cms_menus.py diff --git a/ungleich_page/cms_menus.py b/ungleich_page/cms_menus.py new file mode 100644 index 00000000..ebba3515 --- /dev/null +++ b/ungleich_page/cms_menus.py @@ -0,0 +1,59 @@ +from menus.base import NavigationNode +from menus.menu_pool import menu_pool +from django.utils.translation import ugettext_lazy as _ +from cms.menu_bases import CMSAttachMenu +from cms.templatetags.cms_tags import _get_placeholder +from cms.utils.plugins import get_plugins + + +class TestMenu(CMSAttachMenu): + + name = _("Glasfaser menu") + + def get_nodes(self, request): + nodes = [] + if request and request.current_page: + template_context = { + "request": request, + } + placeholder_name_list = [ + 'Top Section', 'Middle Section', 'Glasfaser Services', + 'Glasfaser About', 'Contact Section' + ] + plugins_list = [ + 'SectionWithImage', 'UngelichContactUsSection', + 'UngelichTextSection', 'Service', 'About' + ] + for placeholder_name in placeholder_name_list: + placeholder = _get_placeholder( + request.current_page, request.current_page, + template_context, placeholder_name + ) + plugins = get_plugins( + request, placeholder, request.current_page.get_template() + ) + for plugin in plugins: + if type(plugin).__name__ in plugins_list: + section_hash = request.build_absolute_uri() + if hasattr(plugin, 'menu_text'): + menu_text = plugin.menu_text + menu_words = menu_text.split() + if len(menu_words) > 0: + section_hash = '{}#{}'.format( + section_hash, + menu_words[0] + ) + else: + continue + newnode = NavigationNode( + menu_text, + url=section_hash, + id="{}-{}".format( + request.current_page.id, plugin.id + ) + ) + nodes.append(newnode) + return nodes + + +menu_pool.register_menu(TestMenu) \ No newline at end of file