momo: improve construction of application menu (#8803)

It will always get a link to the home screen as first item and a link to
refresh the application as the last item.  In the middle it will get links
created from direct page children of the homepage, from the redirection URLs
or the link cell inserted into the page.
This commit is contained in:
Frédéric Péters 2015-10-28 11:38:30 +01:00
parent c7e74f8cdd
commit 314793d71d
2 changed files with 36 additions and 10 deletions

View File

@ -149,17 +149,42 @@ def generate(request, **kwargs):
homepage._children = children
manifest.update(get_page_dict(request, homepage, manifest))
# get real homepage children to construct the application menu
# construct the application menu
manifest['menu'].append('home') # link to home screen
# add real homepage children
menu_children = homepage.get_children()
for menu_child in menu_children:
menu_id = 'menu-%s-%s' % (menu_child.id, menu_child.slug)
link_cells = LinkCell.objects.filter(page_id=menu_child.id)
if link_cells:
# use link info instead of redirect url
link_cell = link_cells[0]
if link_cell.link_page: # internal link
menu_id = 'page-%s-%s' % (link_cell.link_page.slug, link_cell.link_page.id)
else:
menu_id = 'menu-%s-%s' % (menu_child.slug, menu_child.id)
link_context = link_cell.get_cell_extra_context()
manifest['_pages'].append({
'title': link_context['title'],
'external': True,
'url': link_context['url'],
'id': menu_id,
})
else:
menu_id = 'menu-%s-%s' % (menu_child.slug, menu_child.id)
manifest['_pages'].append({
'title': menu_child.title,
'external': True,
'url': menu_child.redirect_url,
'id': menu_id,
})
manifest['menu'].append(menu_id)
manifest['_pages'].append({
'title': menu_child.title,
'external': True,
'url': menu_child.redirect_url,
'id': menu_id,
})
# last item, application refresh
manifest['menu'].append({
'icon': 'fa-refresh',
'id': 'momo-update',
'title': _('Update Application')})
options = MomoOptions.get_object()
manifest['meta'] = {

View File

@ -502,7 +502,8 @@ class LinkCell(CellBase):
return None
return utils.ellipsize(title)
def render(self, context):
def get_cell_extra_context(self):
context = super(LinkCell, self).get_cell_extra_context()
if self.link_page:
context['url'] = self.link_page.get_online_url()
context['title'] = self.title or self.link_page.title
@ -511,7 +512,7 @@ class LinkCell(CellBase):
context['title'] = self.title or self.url
if self.anchor:
context['url'] += '#' + self.anchor
return super(LinkCell, self).render(context)
return context
@register_cell_class