momo: change link cells in <seealso> references (#8107)

This commit is contained in:
Frédéric Péters 2015-08-25 16:38:46 +02:00
parent 68f8855f9f
commit 06ff8acdbf
1 changed files with 28 additions and 6 deletions

View File

@ -30,19 +30,23 @@ from django.views.generic import TemplateView
import ckeditor
from combo.data.models import CellBase, Page
from combo.data.models import CellBase, LinkCell, Page
class MomoManagerView(TemplateView):
template_name = 'momo/manager_home.html'
def get_page_dict(request, page):
def get_page_dict(request, page, manifest):
cells = CellBase.get_cells(page_id=page.id)
page_dict = {
'title': page.title,
'id': 'page-%s' % page.id,
}
link_cells = [x for x in cells if isinstance(x, LinkCell)]
cells = [x for x in cells if not isinstance(x, LinkCell)]
if cells:
context = RequestContext(request, {
'synchronous': True,
@ -52,6 +56,22 @@ def get_page_dict(request, page):
'site_base': request.build_absolute_uri('/')[:-1],
})
page_dict['content'] = '\n'.join([cell.render(context) for cell in cells])
if link_cells:
page_dict['seealso'] = []
for cell in link_cells:
if cell.link_page:
# internal link
page_dict['seealso'].append('page-%s' % cell.link_page.id)
else:
# external link
page_dict['seealso'].append('seealso-%s' % cell.id)
manifest['_pages'].append({
'title': cell.title,
'external': True,
'url': cell.url,
'id': 'seealso-%s' % cell.id})
if page.redirect_url:
page_dict['external'] = True
page_dict['url'] = page.redirect_url
@ -63,12 +83,16 @@ def get_page_dict(request, page):
if children:
page_dict['pages'] = []
for child in children:
page_dict['pages'].append(get_page_dict(request, child))
page_dict['pages'].append(get_page_dict(request, child, manifest))
return page_dict
def generate(request, **kwargs):
manifest = {
'menu': [],
'_pages': []
}
level0_pages = Page.objects.filter(parent=None)
# the application hierarchy is structured that way:
@ -83,12 +107,10 @@ def generate(request, **kwargs):
else:
children.append(page)
homepage._children = children
manifest = get_page_dict(request, homepage)
manifest.update(get_page_dict(request, homepage, manifest))
# get real homepage children to construct the application menu
menu_children = homepage.get_children()
manifest['menu'] = []
manifest['_pages'] = []
for menu_child in menu_children:
menu_id = 'menu-%s-%s' % (menu_child.id, menu_child.slug)
manifest['menu'].append(menu_id)