0001-misc-use-absolute-URIs-for-text-cell-images-in-skele.patch
combo/data/models.py | ||
---|---|---|
742 | 742 |
d[0]['order'] = -1 |
743 | 743 |
return d |
744 | 744 | |
745 |
def get_cell_extra_context(self, context): |
|
746 |
extra_context = super(TextCell, self).get_cell_extra_context(context) |
|
747 |
extra_context['text'] = self.text |
|
748 |
render_skeleton = context.get('render_skeleton') |
|
749 |
if render_skeleton: |
|
750 |
request = context.get('request') |
|
751 |
def sub_src(match): |
|
752 |
url = request.build_absolute_uri(match.group(1)) |
|
753 |
return 'src="%s"' % url |
|
754 |
extra_context['text'] = re.sub(r'src="(.*?)"', sub_src, self.text) |
|
755 |
return extra_context |
|
756 | ||
745 | 757 | |
746 | 758 |
@register_cell_class |
747 | 759 |
class FortuneCell(CellBase): |
combo/public/templates/combo/text-cell.html | ||
---|---|---|
1 | 1 |
{% block cell-content %} |
2 |
{{cell.text|safe}}
|
|
2 |
{{text|safe}} |
|
3 | 3 |
{% endblock %} |
tests/test_public.py | ||
---|---|---|
276 | 276 |
resp = app.get('/__skeleton__/?source=%s' % quote('http://127.0.0.1:8999/')) |
277 | 277 |
assert 'http://testserver/plop' in resp.text |
278 | 278 | |
279 |
# check images in text cell use full URL |
|
280 |
cell = TextCell(page=page, placeholder='footer', order=0) |
|
281 |
cell.text = '<img src="/test/foobar.png"> vs <img src="http://www.example.com/test.png">' |
|
282 |
cell.save() |
|
283 |
resp = app.get('/__skeleton__/?source=%s' % quote('http://127.0.0.1:8999/')) |
|
284 |
assert 'http://testserver/test/foobar.png' in resp.text |
|
285 |
# check absolute URIs are not modified |
|
286 |
assert 'src="http://www.example.com/test.png"' in resp.text |
|
287 | ||
279 | 288 |
# add a bad redirection page (don't use it, do not crash) |
280 | 289 |
page = Page(title='BadRedirection', slug='badredir', template_name='standard', |
281 | 290 |
redirect_url='[foo_bar]') |
282 |
- |