Projet

Général

Profil

0001-manager-mention-template-only-on-absolute-redirect-u.patch

Valentin Deniaud, 10 novembre 2021 17:48

Télécharger (2,91 ko)

Voir les différences:

Subject: [PATCH] manager: mention template only on absolute redirect url
 (#58073)

 combo/manager/templates/combo/page_view.html | 7 ++++++-
 combo/manager/views.py                       | 5 +++++
 tests/test_manager.py                        | 9 +++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)
combo/manager/templates/combo/page_view.html
132 132

  
133 133
{% if object.redirect_url %}
134 134
<div class="infonotice">
135
    <p>{% blocktrans with redirect_url=object.redirect_url %}This page is configured as a redirection to the URL "{{ redirect_url }}", it can also be used as a template for the pages behind this URL.{% endblocktrans %}</p>
135
  <p>
136
    {% blocktrans with redirect_url=object.redirect_url %}This page is configured as a redirection to the URL "{{ redirect_url }}".{% endblocktrans %}
137
    {% if redirect_url_is_absolute %}
138
    {% trans "It can also be used as a template for the pages behind this URL." }
139
    {% endif %}
140
  </p>
136 141
</div>
137 142
{% endif %}
138 143

  
combo/manager/views.py
18 18
import hashlib
19 19
import json
20 20
import tarfile
21
import urllib.parse
21 22
from operator import attrgetter
22 23

  
23 24
from django.conf import settings
......
442 443
            }
443 444
        )
444 445

  
446
        if self.object.redirect_url:
447
            parsed = urllib.parse.urlparse(self.object.redirect_url)
448
            context['redirect_url_is_absolute'] = bool(parsed.netloc)
449

  
445 450
        return context
446 451

  
447 452

  
tests/test_manager.py
278 278
    resp = resp.form.submit()
279 279
    resp = resp.follow()
280 280
    assert 'http://www.example.net' in resp.text
281
    assert 'It can also be used as a template for the pages behind this URL.' in resp.text
281 282
    assert Page.objects.all()[0].redirect_url == 'http://www.example.net'
283
    # redirection (relative url)
284
    resp = resp.click(href='.*/redirection')
285
    resp.form['redirect_url'].value = '/some-page/'
286
    resp = resp.form.submit()
287
    resp = resp.follow()
288
    assert '/some-page/' in resp.text
289
    assert 'It can also be used as a template for the pages behind this URL.' not in resp.text
290
    assert Page.objects.all()[0].redirect_url == '/some-page/'
282 291
    # redirection (error handling)
283 292
    resp = resp.click(href='.*/redirection')
284 293
    resp.form['redirect_url'].value = '{{ foo bar }}'
285
-