Projet

Général

Profil

0001-misc-add-page-absolute-URI-to-cell-rendering-context.patch

Frédéric Péters, 08 décembre 2018 15:26

Télécharger (3,84 ko)

Voir les différences:

Subject: [PATCH] misc: add page absolute URI to cell rendering context (#28777

 .../wcs/templates/combo/wcs/backoffice_submission.html     | 2 +-
 combo/data/models.py                                       | 1 +
 combo/public/views.py                                      | 5 ++++-
 tests/test_public.py                                       | 7 +++++--
 4 files changed, 11 insertions(+), 4 deletions(-)
combo/apps/wcs/templates/combo/wcs/backoffice_submission.html
9 9
  {% for category_formdefs in categories_formdefs %}
10 10
    <li><h4>{{ category_formdefs.grouper }}</h4></li>
11 11
    {% for formdef in category_formdefs.list|dictsort:"title" %}
12
      <li><a href="{{formdef.backoffice_submission_url}}?NameID={{name_id}}&ReturnURL={% page_absolute_url cell.page %}">{{formdef.title}}</a></li>
12
      <li><a href="{{formdef.backoffice_submission_url}}?NameID={{name_id}}&ReturnURL={{ absolute_uri|iriencode }}">{{formdef.title}}</a></li>
13 13
    {% endfor %}
14 14
  {% endfor %}
15 15
</ul>
combo/data/models.py
692 692
            'site_base': request.build_absolute_uri('/')[:-1],
693 693
            'synchronous': True,
694 694
            'user': None, # compat
695
            'absolute_uri': request.build_absolute_uri,
695 696
        }
696 697
        if not self.is_relevant(context):
697 698
            return ''
combo/public/views.py
143 143
        'cell': cell,
144 144
        'synchronous': True,
145 145
        'site_base': request.build_absolute_uri('/')[:-1],
146
        'absolute_uri': request.build_absolute_uri
146 147
    }
147 148
    if request.GET.get('ctx'):
148 149
        context.update(signing.loads(request.GET['ctx']))
......
356 357

  
357 358

  
358 359
def page(request):
359
    request.extra_context_data = {}
360
    request.extra_context_data = {
361
        'absolute_uri': request.build_absolute_uri()
362
    }
360 363
    url = request.path_info
361 364
    parts = [x for x in request.path_info.strip('/').split('/') if x]
362 365
    if len(parts) == 1 and parts[0] == 'index':
tests/test_public.py
727 727
    cell.save()
728 728

  
729 729
    cell2 = JsonCell(page=page3, url='http://example.net', order=0, placeholder='content')
730
    cell2.template_string = 'AA{{ blah }}BB'
730
    cell2.template_string = 'AA{{ blah }}BB{{ absolute_uri }}CC'
731 731
    cell2.save()
732 732

  
733 733
    with mock.patch('combo.utils.requests.get') as requests_get:
......
746 746
        # check sub page
747 747
        resp = app.get('/users/whatever/plop/', status=404)
748 748
        resp = app.get('/users/whatever/blah/', status=200)
749
        assert 'AAwhateverBB' in resp.text
749
        cell_url = re.findall(r'data-ajax-cell-url="(.*)"', resp.text)[0]
750
        extra_ctx = re.findall(r'data-extra-context="(.*)"', resp.text)[0]
751
        resp = app.get(cell_url + '?ctx=' + extra_ctx)
752
        assert resp.text == 'AAwhateverBBhttp://testserver/users/whatever/blah/CC'
750 753

  
751 754
        # custom behaviour for <user_id>, it will add the user to context
752 755
        page2.sub_slug = '(?P<user_id>[0-9]+)'
753
-