def events(self): instance = CMSNewsAndEventsPlugin() instance.display = "events" instance.order_by = "date" instance.format = "details" instance.type = "for_place" instance.place = self instance.show_venue = False events = get_news_and_events(instance) return events
def recursive(self, request, nodes): for child in nodes: try: ancestor = child.ancestor except AttributeError: ancestor = False try: selected = child.selected except AttributeError: selected = False if selected or ancestor: # does the entity have an entity? try: page = Page.objects.get(id=child.id, entity__isnull=False) entity = page.entity.all()[0] # does this entity have a news page? if entity.auto_news_page and "news" in menu_tests: # invoke the plugin to find out more instance = NewsAndEventsPlugin() instance.entity = entity instance.type = "main_page" instance.limit_to = news_and_events_list_default_limit instance.view = "current" get_news_and_events(instance) # are there actually any new/events items to show? if not, no menu if instance.news or instance.other_news or instance.events or instance.other_events: menutitle = entity.news_page_menu_title new_node = NavigationNode(mark_safe(menutitle), entity.get_related_info_page_url('news-and-events'), None) if new_node.get_absolute_url() in request.page_path: new_node.selected = True child.selected=False if instance.other_news and "news_archive" in menu_tests: new_sub_node = NavigationNode(mark_safe("News archive"), entity.get_related_info_page_url('news-archive'), None ) if request.page_path == new_sub_node.get_absolute_url(): new_sub_node.selected = True new_node.selected=False new_node.children.append(new_sub_node) if any("all-forthcoming" in d.itervalues() for d in instance.other_events) and "forthcoming_events" in menu_tests: new_sub_node = NavigationNode(mark_safe("All forthcoming events"), entity.get_related_info_page_url('forthcoming-events'), None ) if request.page_path == new_sub_node.get_absolute_url(): new_sub_node.selected = True new_node.selected=False new_node.children.append(new_sub_node) if any("previous-events" in d.itervalues() for d in instance.other_events) and "previous_events" in menu_tests: new_sub_node = NavigationNode(mark_safe("Previous events"), entity.get_related_info_page_url('previous-events'), None ) if request.page_path == new_sub_node.get_absolute_url(): new_sub_node.selected = True new_node.selected=False new_node.children.append(new_sub_node) child.children.append(new_node) if entity.auto_contacts_page and "contacts" in menu_tests: menutitle = entity.contacts_page_menu_title new_node = NavigationNode(mark_safe(menutitle), entity.get_related_info_page_url('contact'), None) if new_node.get_absolute_url() in request.page_path: new_node.selected = True child.selected=False child.children.append(new_node) if getattr(entity, "auto_vacancies_page", None) and "vacancies" in menu_tests: menutitle = entity.vacancies_page_menu_title new_node = NavigationNode(mark_safe(menutitle), entity.get_related_info_page_url('vacancies-and-studentships'), None) if request.page_path == new_node.get_absolute_url(): new_node.selected = True child.selected=False child.children.append(new_node) if getattr(entity, "auto_publications_page", None) and entity.auto_publications_page and "publications" in menu_tests: menutitle = entity.publications_page_menu_title new_node = NavigationNode(mark_safe(menutitle), entity.get_related_info_page_url('publications'), None) if request.page_path == new_node.get_absolute_url(): new_node.selected = True child.selected=False child.children.append(new_node) except Page.DoesNotExist: pass self.recursive(request, child.children)