public: make skeleton available to all known services (#8560)
This commit is contained in:
parent
c845d86235
commit
24d2a77f53
|
@ -112,7 +112,13 @@ def skeleton(request):
|
|||
#
|
||||
# It takes a ?source= parameter that should contain the URL we want a
|
||||
# template for; it will be used to match the corresponding page, and thus
|
||||
# the corresponding content. If there's no matching page, an error will be
|
||||
# the corresponding content.
|
||||
#
|
||||
# If there's no matching page, the ?source= parameter will be evaluated
|
||||
# against the known services (settings.KNOWN_SERVICES) and an empty page
|
||||
# will be created to be used as skeleton.
|
||||
#
|
||||
# If there was no matching page and no matching service an error will be
|
||||
# raised. (403 Access Forbidden)
|
||||
#
|
||||
# While placeholders holding cells will get their cells rendered, empty
|
||||
|
@ -143,11 +149,25 @@ def skeleton(request):
|
|||
if urlparse.urlparse(page.redirect_url).netloc == netloc:
|
||||
selected_page = page
|
||||
break
|
||||
|
||||
if selected_page is None:
|
||||
# if there's still no page found, look in KNOWN_SERVICES, and
|
||||
# return an empty page as template
|
||||
for service_id in settings.KNOWN_SERVICES or {}:
|
||||
for service_key in settings.KNOWN_SERVICES[service_id]:
|
||||
service = settings.KNOWN_SERVICES[service_id][service_key]
|
||||
if urlparse.urlparse(service.get('url')).netloc == netloc:
|
||||
selected_page = Page()
|
||||
selected_page.template_name = 'standard'
|
||||
break
|
||||
else:
|
||||
continue
|
||||
break
|
||||
else:
|
||||
raise PermissionDenied()
|
||||
|
||||
pages = list(selected_page.get_parents_and_self())
|
||||
cells = CellBase.get_cells(page_id=page.id)
|
||||
cells = CellBase.get_cells(page_id=selected_page.id)
|
||||
extend_with_locked_placeholders_cells(cells, selected_page, pages)
|
||||
|
||||
combo_template = settings.COMBO_PUBLIC_TEMPLATES[selected_page.template_name]
|
||||
|
|
|
@ -111,6 +111,10 @@ def test_page_skeleton():
|
|||
assert '{% block placeholder-content %}{% block content %}{% endblock %}{% endblock %}' in resp.body
|
||||
assert '{% block placeholder-footer %}{% block footer %}{% endblock %}{% endblock %}' in resp.body
|
||||
|
||||
# settings.KNOWN_SERVICES match
|
||||
resp = app.get('/__skeleton__/?source=%s' % urllib.quote('http://127.0.0.1:8999/'))
|
||||
assert '{% block placeholder-content %}{% block content %}{% endblock %}{% endblock %}' in resp.body
|
||||
|
||||
# no match
|
||||
resp = app.get('/__skeleton__/?source=%s' % urllib.quote('http://example.com/foo/bar'), status=403)
|
||||
|
||||
|
|
Loading…
Reference in New Issue