forked from geosolutions-it/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Populate clients menus from menus models (#284)
- Loading branch information
1 parent
5dd41db
commit 0d2db76
Showing
7 changed files
with
91 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django import template | ||
from geonode.base.models import Menu, MenuItem | ||
|
||
register = template.Library() | ||
|
||
def _handle_single_item(menu_item): | ||
m_item = {} | ||
m_item['type'] = 'link' | ||
m_item['href'] = menu_item.url | ||
m_item['label'] = menu_item.title | ||
if menu_item.blank_target: | ||
m_item['target'] = '_blank' | ||
return m_item | ||
|
||
@register.simple_tag | ||
def get_menu_json(placeholder_name): | ||
menus = { | ||
m: MenuItem.objects.filter(menu=m).order_by('order') | ||
for m in Menu.objects.filter(placeholder__name=placeholder_name) | ||
} | ||
ms = [] | ||
for menu, menu_items in menus.items(): | ||
if len(menu_items) > 1: | ||
m = {} | ||
m['label'] = menu.title | ||
m['type'] = 'dropdown' | ||
m['items'] = [] | ||
for menu_item in menu_items: | ||
m_item = _handle_single_item(menu_item) | ||
m['items'].append(m_item) | ||
|
||
ms.append(m) | ||
if len(menu_items) == 1: | ||
m = _handle_single_item(menu_items.first()) | ||
ms.append(m) | ||
return ms |