misc: create full URL in link cell used in skeletons (#16874)
This commit is contained in:
parent
3081c4286e
commit
0c2fc1db03
|
@ -21,6 +21,7 @@ import logging
|
|||
import os
|
||||
import requests
|
||||
import subprocess
|
||||
import urlparse
|
||||
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
|
@ -638,6 +639,8 @@ class LinkCell(CellBase):
|
|||
return utils.ellipsize(title)
|
||||
|
||||
def get_cell_extra_context(self, context):
|
||||
render_skeleton = context.get('render_skeleton')
|
||||
request = context.get('request')
|
||||
context = super(LinkCell, self).get_cell_extra_context(context)
|
||||
if self.link_page:
|
||||
context['url'] = self.link_page.get_online_url()
|
||||
|
@ -647,6 +650,9 @@ class LinkCell(CellBase):
|
|||
context['title'] = self.title or self.url
|
||||
if self.anchor:
|
||||
context['url'] += '#' + self.anchor
|
||||
if render_skeleton and not urlparse.urlparse(context['url']).netloc:
|
||||
# create full URL when used in a skeleton
|
||||
context['url'] = request.build_absolute_uri(context['url'])
|
||||
return context
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ from django.core.urlresolvers import reverse
|
|||
from django.test import override_settings
|
||||
|
||||
from combo.wsgi import application
|
||||
from combo.data.models import Page, CellBase, TextCell, ParentContentCell, FeedCell
|
||||
from combo.data.models import Page, CellBase, TextCell, ParentContentCell, FeedCell, LinkCell
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
@ -142,6 +142,14 @@ def test_page_skeleton(app):
|
|||
assert not '{% block placeholder-footer %}{% block footer %}{% endblock %}{% endblock %}' in resp.body
|
||||
assert 'Foobar' in resp.body
|
||||
|
||||
# check link cells provide a full URL
|
||||
other_page = Page(title='Plop', slug='plop', template_name='standard')
|
||||
other_page.save()
|
||||
cell = LinkCell(page=page, placeholder='footer', link_page=other_page, order=0)
|
||||
cell.save()
|
||||
resp = app.get('/__skeleton__/?source=%s' % urllib.quote('http://127.0.0.1:8999/'))
|
||||
assert 'http://testserver/plop' in resp.body
|
||||
|
||||
def test_subpage_location(app):
|
||||
Page.objects.all().delete()
|
||||
|
||||
|
|
Loading…
Reference in New Issue