0001-wcs-don-t-display-empty-sites-in-BackofficeSubmissio.patch
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 | ||
---|---|---|
1 | 1 |
function combo_load_cell(elem) { |
2 | 2 |
var $elem = $(elem); |
3 | 3 |
var url = $elem.data('ajax-cell-url'); |
4 |
$elem.removeClass('empty-cell'); |
|
4 | 5 |
var extra_context = $elem.data('extra-context'); |
5 | 6 |
$.support.cors = true; /* IE9 */ |
6 | 7 |
var qs; |
... | ... | |
25 | 26 |
} else { |
26 | 27 |
$elem.find('> div').html(data); |
27 | 28 |
} |
29 |
if (! $elem.find('> div').children().length) { |
|
30 |
$elem.addClass('empty-cell'); |
|
31 |
} |
|
28 | 32 |
$(document).trigger('combo:cell-loaded', $elem); |
29 | 33 |
}, |
30 | 34 |
error: function(error) { |
... | ... | |
81 | 85 |
$('[data-ajax-cell-must-load]').each(function(idx, elem) { |
82 | 86 |
combo_load_cell($(elem).parents('div.cell')[0]); |
83 | 87 |
}); |
88 |
$('div.cell > div').each(function(idx, elem) { |
|
89 |
if (! $('[data-ajax-cell-must-load]', $(elem)).length && ! $(elem).children().length) { |
|
90 |
$(elem).parent().addClass('empty-cell'); |
|
91 |
} |
|
92 |
}); |
|
84 | 93 | |
85 | 94 |
/* utility functions and events, for themes */ |
86 | 95 |
$('.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 |
- |