| 
									
										
										
										
											2017-10-19 13:39:56 +02:00
										 |  |  | 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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-19 19:47:53 +02:00
										 |  |  | class GlasfaserMenu(CMSAttachMenu): | 
					
						
							| 
									
										
										
										
											2017-10-19 13:39:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     name = _("Glasfaser menu") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def get_nodes(self, request): | 
					
						
							|  |  |  |         nodes = [] | 
					
						
							| 
									
										
										
										
											2017-10-20 12:31:12 +02:00
										 |  |  |         glasfaser_cms = 'ungleich_page/glasfaser_cms_page.html' | 
					
						
							| 
									
										
										
										
											2017-11-24 22:45:28 +01:00
										 |  |  |         if (request and request.current_page and | 
					
						
							| 
									
										
										
										
											2017-11-26 01:12:16 +01:00
										 |  |  |                 request.current_page.get_template() == glasfaser_cms): | 
					
						
							| 
									
										
										
										
											2017-10-19 13:39:56 +02:00
										 |  |  |             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 | 
					
						
							| 
									
										
										
										
											2017-10-19 16:04:18 +02:00
										 |  |  |                             if menu_text.strip() == '': | 
					
						
							|  |  |  |                                 continue | 
					
						
							| 
									
										
										
										
											2017-10-19 13:39:56 +02:00
										 |  |  |                             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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-19 19:47:53 +02:00
										 |  |  | menu_pool.register_menu(GlasfaserMenu) |