Ejemplo n.º 1
0
    def events(self):
        from news_and_events.models import NewsAndEventsPlugin

        # invoke the plugin to find out more
        instance = NewsAndEventsPlugin()
        instance.display = "events"
        instance.type = "for_place"
        instance.place = self
        instance.view = "current"
        instance.format = "details image"

        # create an instance of the plugin to see if the menu should have items
        plugin = CMSNewsAndEventsPlugin()
        plugin.get_items(instance)
        plugin.add_links_to_other_items(instance)
        plugin.set_image_format(instance)
        plugin.set_limits_and_indexes(instance)
        instance.lists = plugin.lists
        return instance
Ejemplo n.º 2
0
    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
            
            # expand branches selectvely, or expand all    
            if selected or ancestor or EXPAND_ALL_MENU_BRANCHES:
                # 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 = "menu"
                        instance.limit_to = MAIN_NEWS_EVENTS_PAGE_LIST_LENGTH
                        instance.view = "current"
                        context = RequestContext(request)
                        
                        # create an instance of the plugin to see if the menu should have items
                        plugin = CMSNewsAndEventsPlugin()   
                        plugin.get_items(instance)
                        plugin.add_links_to_other_items(instance)    
                        
                        # assume there's no menu item required
                        show_menu_item = False
                                               
                        menutitle = entity.news_page_menu_title

                        # create a new node
                        new_node = NavigationNode(
                            mark_safe(menutitle), 
                            entity.get_related_info_page_url('news-and-events'), 
                            None
                            )
                            
                        # go through the lists of items
                        for item in plugin.lists:
                            if item["items"]:
                                show_menu_item = True

                            # and go through the other_items lists for each
                            for other_item in item["other_items"]:
                                new_sub_node = NavigationNode(
                                    mark_safe(other_item["title"]), 
                                    other_item["link"], 
                                    None )
                                if request.page_path == new_sub_node.get_absolute_url():
                                    new_sub_node.selected = True
                                    new_node.selected = False

                                show_menu_item = True
                                new_node.children.append(new_sub_node)

                        if show_menu_item:
                            # is this node the one we are currently looking at?
                            if new_node.get_absolute_url() == request.page_path:
                                new_node.selected = True
                                child.selected = False
                            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:

                        instance = VacanciesPlugin()
                        instance.entity = entity
                        instance.type = "menu"
                        instance.limit_to = MAIN_NEWS_EVENTS_PAGE_LIST_LENGTH
                        instance.view = "current"
                        context = RequestContext(request)
                                             
                        # create an instance of the plugin to see if the menu should have items
                        plugin = CMSVacanciesPlugin()   
                        plugin.get_items(instance)
                        plugin.add_links_to_other_items(instance)    

                        # assume there's no menu item required
                        show_menu_item = False

                        # are there actually any vacancies/studentships items to show? if not, no menu
                        for item in plugin.lists:
                            if item["items"]:
                                show_menu_item = True
                                
                        if show_menu_item:
                            print "menu"
                            print plugin.lists
                            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)