Projet

Général

Profil

0001-wcs-don-t-display-empty-sites-in-BackofficeSubmissio.patch

Lauréline Guérin, 20 avril 2020 09:30

Télécharger (5,59 ko)

Voir les différences:

Subject: [PATCH] wcs: don't display empty sites in BackofficeSubmissionCell
 (#41090)

 combo/apps/wcs/models.py                              | 10 ++++++++--
 .../templates/combo/wcs/backoffice_submission.html    |  8 ++++++--
 combo/public/static/js/combo.public.js                | 11 +++++++++++
 tests/test_wcs.py                                     |  9 ++++++++-
 4 files changed, 33 insertions(+), 5 deletions(-)
combo/apps/wcs/models.py
754 754

  
755 755
    def get_cell_extra_context(self, context):
756 756
        context = super(BackofficeSubmissionCell, self).get_cell_extra_context(context)
757
        all_formdefs = context.pop('all_formdefs')
758
        formdefs = {}
757 759
        # add a fake category where it's missing
758
        for site_formdefs in context['all_formdefs'].values():
760
        for key, site_formdefs in all_formdefs.items():
761
            if not site_formdefs['data']:
762
                continue
763
            formdefs[key] = site_formdefs
759 764
            for formdef in site_formdefs['data']:
760
                if not 'category' in formdef:
765
                if 'category' not in formdef:
761 766
                    formdef['category'] = _('Misc')
767
        context['all_formdefs'] = formdefs
762 768
        return context
combo/apps/wcs/templates/combo/wcs/backoffice_submission.html
1 1
{% load i18n %}
2 2
{% block cell-content %}
3
{% if all_formdefs %}
3 4
<h2>{% trans "New Form" %}</h2>
4 5
{% for site_formdefs in all_formdefs.values %}
5
  <div class="links-list">
6
<div class="links-list">
6 7
  {% if all_formdefs.keys|length > 1 %}<h3>{{ site_formdefs.title }}</h3>{% endif %}
7 8
  <ul>
8 9
  {% regroup site_formdefs.data|dictsort:"category" by category as categories_formdefs %}
......
12 13
      <li><a href="{{formdef.backoffice_submission_url}}?NameID={{name_id}}&ReturnURL={{ absolute_uri|iriencode }}">{{formdef.title}}</a></li>
13 14
    {% endfor %}
14 15
  {% endfor %}
15
</ul>
16
  </ul>
16 17
</div>
17 18
{% endfor %}
19
{% elif not combo_hide_empty_message %}
20
<div class="empty-message"><p>{% trans "There are no possible backoffice submissions." %}</p></div>
21
{% endif %}
18 22
{% endblock %}
combo/public/static/js/combo.public.js
25 25
              } else {
26 26
                  $elem.find('> div').html(data);
27 27
              }
28
              if (! $elem.find('> div').children().length) {
29
                $elem.addClass('empty-cell');
30
              } else {
31
                $elem.removeClass('empty-cell')
32
              }
28 33
              $(document).trigger('combo:cell-loaded', $elem);
29 34
          },
30 35
          error: function(error) {
31 36
              var msg = $(elem).data('ajax-cell-error-message');
32 37
              if (!msg) msg = 'Unknown error (code: ' + error.status + ')';
33 38
              $elem
39
                  .removeClass('empty-cell')
34 40
                  .find('.loading')
35 41
                  .addClass('error-loading')
36 42
                  .html('<span class="loading-message">' + msg + '</span>');
......
81 87
  $('[data-ajax-cell-must-load]').each(function(idx, elem) {
82 88
    combo_load_cell($(elem).parents('div.cell')[0]);
83 89
  });
90
  $('div.cell > div').each(function(idx, elem) {
91
    if (! $('[data-ajax-cell-must-load]', $(elem)).length && ! $(elem).children().length) {
92
      $(elem).parent().addClass('empty-cell');
93
    }
94
  });
84 95

  
85 96
  /* utility functions and events, for themes */
86 97
  $('.togglable').on('click', function() {
tests/test_wcs.py
1172 1172
    assert 'tracking-code' not in search_engines.keys()
1173 1173
    assert len([x for x in search_engines.keys() if x.startswith('formdata:')]) == 0
1174 1174

  
1175

  
1175 1176
@wcs_present
1176 1177
def test_backoffice_submission_cell_render(context):
1177 1178
    page = Page(title='xxx', slug='test_backoffice_submission_cell_render', template_name='standard')
......
1180 1181
    cell.wcs_site = 'default'
1181 1182
    cell.save()
1182 1183

  
1183
    context['synchronous'] = True # to get fresh content
1184
    context['synchronous'] = True  # to get fresh content
1184 1185

  
1185 1186
    result = cell.render(context)
1186 1187
    assert '/backoffice/submission/a-private-form/' not in result
1188
    assert context['all_formdefs'] == {}
1189
    assert 'h2' not in result
1187 1190

  
1188 1191
    context['request'].user = MockUser()
1189 1192

  
1190 1193
    result = cell.render(context)
1191 1194
    assert '/backoffice/submission/a-private-form/' not in result
1195
    assert context['all_formdefs'] == {}
1196
    assert 'h2' not in result
1192 1197

  
1193 1198
    class MockUser2(MockUser):
1194 1199
        email = 'foo2@example.net'
......
1196 1201

  
1197 1202
    result = cell.render(context)
1198 1203
    assert '/backoffice/submission/a-private-form/' in result
1204
    assert list(context['all_formdefs'].keys()) == ['default']
1205
    assert 'h2' in result
1199 1206

  
1200 1207

  
1201 1208
@wcs_present
1202
-