Пример #1
0
    def list(req, pager, **kwargs):
        if pager.order not in (MenuItem.ID, MenuItem.PARENT, MenuItem.ORDER,
                               'title', 'locale'):
            pager.order = MenuItem.ORDER

        if pager.limit == -1 and pager.order == MenuItem.ORDER:
            rows = Item.full_tree(req, MenuItem, **kwargs)
        else:
            rows = Item.list(req, MenuItem, pager, **kwargs)

        items = []
        for row in rows:
            item = MenuItem(row[MenuItem.ID])
            item.parent = row[MenuItem.PARENT]
            item.next = row[MenuItem.NEXT]
            item.order = row[MenuItem.ORDER]
            item.title = row['title']
            item.link = row['link']
            item.state = row['state']
            item.locale = row['locale']
            item.level = row['_level'] if '_level' in row else 0
            item.md5 = md5(json.dumps(item.__dict__)).hexdigest()
            items.append(item)
        return items
Пример #2
0
    def get_menu(req):
        rows = Item.full_tree(req, MenuItem)
        items = {None: menu.Menu('')}
        for row in rows:
            if row[MenuItem.PARENT]:
                items[row[MenuItem.PARENT]] = menu.Menu('', role='static-menu')

        for row in rows:
            if row['state'] == 0:
                continue            # only active items
            item = items.get(row[MenuItem.ID],
                             menu.Item(row['link'], role='static-link'))
            item.label = row['title']
            item.locale = row['locale']

            items[row[MenuItem.PARENT]].append(item)

        return items[None]