diff options
Diffstat (limited to 'ishtar_common/menus.py')
| -rw-r--r-- | ishtar_common/menus.py | 77 | 
1 files changed, 77 insertions, 0 deletions
| diff --git a/ishtar_common/menus.py b/ishtar_common/menus.py index 7d24b0fd2..3741c6cac 100644 --- a/ishtar_common/menus.py +++ b/ishtar_common/menus.py @@ -22,6 +22,7 @@ Menus  """  from django.conf import settings +from django.core.urlresolvers import reverse  _extra_menus = []  # collect menu from INSTALLED_APPS @@ -56,6 +57,14 @@ class Menu:          self.initialized = False          self.items = {}          self.current_action = current_action +        self.current_section = None +        self.current_url = None +        self.current_section = "" +        self.current_sections = [] +        self.current_subsection = "" +        self.current_subsections = [] +        self.current_subsubsection = "" +        self.current_subsubsections = []          self.selected_idx = None          self.session = session          self.items_by_idx = {} @@ -79,5 +88,73 @@ class Menu:                  self.selected_idx = idx          self.initialized = True +    def get_current_selection(self, current_path): +        # current_section, current_subsection, etc. are current labels +        # current_sections, current_subsections, etc. are list of: +        # (label, url, has_children) + +        self.current_section = '' +        self.current_sections = [] + +        self.current_subsection = "" +        self.current_subsections = [] + +        self.current_subsubsection = "" +        self.current_subsubsections = [] +        self.current_url = None +        for section in self.childs: +            if not section.available: +                continue +            section_url = None +            subsections = [] +            if not self.current_section: +                # initialize by default with the first section +                self.current_section = section.label +            selected_section = None + +            for menu_item in section.childs: +                if not menu_item.available: +                    continue +                if not hasattr(menu_item, 'childs') or not menu_item.childs: +                    item_url = reverse('action', args=[menu_item.idx]) +                    if not section_url: +                        section_url = item_url +                    subsections.append([menu_item.label, item_url, False]) +                    if item_url in current_path: +                        self.current_url = item_url +                        self.current_section = section.label +                        self.current_subsection = menu_item.label +                        selected_section = True +                    continue +                subsection_url = None +                selected_subsection = None +                subsubsections = [] +                for menu_subitem in menu_item.childs: +                    if not menu_subitem.available: +                        continue +                    item_url = reverse('action', args=[menu_subitem.idx]) +                    if not section_url: +                        section_url = item_url +                    if not subsection_url: +                        subsection_url = item_url +                        subsections.append([menu_item.label, item_url, True]) +                    subsubsections.append([menu_subitem.label, item_url, False]) +                    if item_url in current_path: +                        self.current_url = item_url +                        self.current_section = section.label +                        self.current_subsection = menu_item.label +                        self.current_subsubsection = menu_subitem.label +                        selected_section = True +                        selected_subsection = True +                if selected_subsection: +                    self.current_subsubsections = subsubsections + +            if selected_section: +                self.current_subsections = subsections +            if not section_url: +                section_url = "/" +            self.current_sections.append([section.label, section_url, +                                          bool(subsections)]) +  menu = Menu(None)  menu.init() | 
