manager: fix pluralization of imported agendas messages (#35571)
This commit is contained in:
parent
f5b09ae137
commit
bdb4d985d6
|
@ -109,13 +109,15 @@ class AgendasImportView(FormView):
|
|||
message1 = _('No agenda created.')
|
||||
else:
|
||||
message1 = ungettext('An agenda has been created.',
|
||||
'%(count)d agendas have been created.', results['created'])
|
||||
'%(count)d agendas have been created.', results['created']) % {
|
||||
'count': results['created']}
|
||||
|
||||
if results.get('updated') == 0:
|
||||
message2 = _('No agenda updated.')
|
||||
else:
|
||||
message2 = ungettext('An agenda has been updated.',
|
||||
'%(count)d agendas have been updated.', results['updated'])
|
||||
'%(count)d agendas have been updated.', results['updated']) % {
|
||||
'count': results['updated']}
|
||||
messages.info(self.request, u'%s %s' % (message1, message2))
|
||||
|
||||
return super(AgendasImportView, self).form_valid(form)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import copy
|
||||
import json
|
||||
|
||||
from django.contrib.auth.models import User, Group
|
||||
|
@ -1546,7 +1547,7 @@ def test_import_agenda(app, admin_user):
|
|||
resp = app.get('/manage/agendas/%s/settings' % agenda.id)
|
||||
resp = resp.click('Export')
|
||||
assert resp.headers['content-type'] == 'application/json'
|
||||
agenda_export = resp.body
|
||||
agenda_export = resp.text
|
||||
|
||||
# invalid json
|
||||
resp = app.get('/manage/', status=200)
|
||||
|
@ -1565,7 +1566,7 @@ def test_import_agenda(app, admin_user):
|
|||
# existing agenda
|
||||
resp = app.get('/manage/', status=200)
|
||||
resp = resp.click('Import')
|
||||
resp.form['agendas_json'] = Upload('export.json', agenda_export, 'application/json')
|
||||
resp.form['agendas_json'] = Upload('export.json', agenda_export.encode('utf-8'), 'application/json')
|
||||
resp = resp.form.submit().follow()
|
||||
assert 'No agenda created. An agenda has been updated.' in resp.text
|
||||
assert Agenda.objects.count() == 1
|
||||
|
@ -1574,11 +1575,35 @@ def test_import_agenda(app, admin_user):
|
|||
Agenda.objects.all().delete()
|
||||
resp = app.get('/manage/', status=200)
|
||||
resp = resp.click('Import')
|
||||
resp.form['agendas_json'] = Upload('export.json', agenda_export, 'application/json')
|
||||
resp.form['agendas_json'] = Upload('export.json', agenda_export.encode('utf-8'), 'application/json')
|
||||
resp = resp.form.submit().follow()
|
||||
assert 'An agenda has been created. No agenda updated.' in resp.text
|
||||
assert Agenda.objects.count() == 1
|
||||
|
||||
# multiple agendas
|
||||
agendas = json.loads(agenda_export)
|
||||
agendas['agendas'].append(copy.copy(agendas['agendas'][0]))
|
||||
agendas['agendas'].append(copy.copy(agendas['agendas'][0]))
|
||||
agendas['agendas'][1]['label'] = 'Foo bar 2'
|
||||
agendas['agendas'][1]['slug'] = 'foo-bar-2'
|
||||
agendas['agendas'][2]['label'] = 'Foo bar 3'
|
||||
agendas['agendas'][2]['slug'] = 'foo-bar-3'
|
||||
|
||||
resp = app.get('/manage/', status=200)
|
||||
resp = resp.click('Import')
|
||||
resp.form['agendas_json'] = Upload('export.json', json.dumps(agendas).encode('utf-8'), 'application/json')
|
||||
resp = resp.form.submit().follow()
|
||||
assert '2 agendas have been created. An agenda has been updated.' in resp.text
|
||||
assert Agenda.objects.count() == 3
|
||||
|
||||
Agenda.objects.all().delete()
|
||||
resp = app.get('/manage/', status=200)
|
||||
resp = resp.click('Import')
|
||||
resp.form['agendas_json'] = Upload('export.json', json.dumps(agendas).encode('utf-8'), 'application/json')
|
||||
resp = resp.form.submit().follow()
|
||||
assert '3 agendas have been created. No agenda updated.' in resp.text
|
||||
assert Agenda.objects.count() == 3
|
||||
|
||||
# reference to unknown group
|
||||
agenda_export_dict = json.loads(force_text(agenda_export))
|
||||
agenda_export_dict['agendas'][0]['permissions']['view'] = u'gé1'
|
||||
|
|
Loading…
Reference in New Issue