Skip to content

Commit

Permalink
fix: menu items with publications
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-filicetti committed May 6, 2021
1 parent 4f40892 commit 581e637
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_requirements(fname='requirements.txt'):

setup(
name="unicms",
version='0.13.3',
version='0.13.4',
description="uniCMS is a Django Web Content Management System",
author='Giuseppe De Marco, Francesco Filicetti',
author_email='giuseppe.demarco@unical.it, francesco.filicetti@unical.it',
Expand Down
5 changes: 4 additions & 1 deletion src/cms/menus/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ def __init__(self, *args, **kwargs):
setattr(self.fields['webpath'],
FORM_SOURCE_LABEL,
reverse('unicms_api:webpath-all-options'))
setattr(self.fields['publication'],
FORM_SOURCE_LABEL,
reverse('unicms_api:editorial-board-publications-options'))
setattr(self.fields['inherited_content'],
FORM_SOURCE_LABEL,
reverse('unicms_api:editorial-board-publications-options'))

class Meta:
model = NavigationBarItem
fields = ['menu', 'name', 'webpath', 'parent', 'url',
# 'publication',
'publication',
'inherited_content',
'order', 'is_active']

Expand Down
2 changes: 2 additions & 0 deletions src/cms/menus/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def to_representation(self, instance):
data['webpath'] = webpath.data
inherited_content = PublicationSerializer(instance.inherited_content)
data['inherited_content'] = inherited_content.data
publication = PublicationSerializer(instance.publication)
data['publication'] = publication.data
return data

class Meta:
Expand Down
23 changes: 14 additions & 9 deletions src/cms/menus/templatetags/unicms_menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ def load_item_inherited_content(context, item):
return item.inherited_content


def _loop_item_childs(item, path, language):
webpath = item.webpath
if webpath and not webpath.is_alias:
if path == webpath.get_full_path():
return {'item': item,
'childs': item.get_childs(lang=language)}
for child in item.get_childs():
result = _loop_item_childs(child, path, language)
if result: return result
return {}


@register.simple_tag(takes_context=True)
def load_current_item_from_menu(context):
_func_name = 'load_current_item_from_menu'
Expand All @@ -91,12 +103,5 @@ def load_current_item_from_menu(context):
path = append_slash(request.path)

for item in context['items']:
webpath = item.webpath
if webpath and not webpath.is_alias:
if path == webpath.get_full_path():
return item.get_childs(lang=language)
for child in item.get_childs():
webpath = child.webpath
if webpath and not webpath.is_alias:
if path == webpath.get_full_path():
return child.get_childs(lang=language)
result = _loop_item_childs(item, path, language)
if result: return result

0 comments on commit 581e637

Please sign in to comment.