settings: add a warning on import page if there's content already (#54125)

This commit is contained in:
Frédéric Péters 2021-05-31 09:44:38 +02:00
parent 90f7469ccc
commit bc887791d8
2 changed files with 13 additions and 1 deletions

View File

@ -190,6 +190,7 @@ def test_settings_export_import(pub):
assert FormDef.count() == 0
resp = app.get('/backoffice/settings/import')
assert 'This site has existing' not in resp.text
resp = resp.form.submit('cancel')
resp = app.get('/backoffice/settings/import')
@ -287,6 +288,10 @@ def test_settings_export_import(pub):
filelist = zipf.namelist()
assert len([x for x in filelist if 'roles_xml/' in x]) == 0
# check a warning is displayed if there's some content already
resp = app.get('/backoffice/settings/import')
assert 'This site has existing' in resp.text
# check an error is displayed if such an import is then used and roles are
# missing.
FormDef.wipe()

View File

@ -600,7 +600,7 @@ class SettingsDirectory(QommonSettingsDirectory):
r += htmltext('<dl>')
r += htmltext('<dt><a href="import">%s</a></dt> <dd>%s</dd>') % (
_('Import'),
_('Import data from another site'),
_('Initialise with data from another site'),
)
r += htmltext('<dt><a href="export">%s</a></dt> <dd>%s</dd>') % (
_('Export'),
@ -1163,7 +1163,14 @@ class SettingsDirectory(QommonSettingsDirectory):
html_top('settings', title=_('Import'))
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Import')
if FormDef.count() or CardDef.count() or Workflow.count():
r += htmltext('<div class="warningnotice">%s</div>') % _(
'This site has existing forms, cards or workflows, beware re-importing '
'content is dangerous and will probably break existing data and configuration.'
)
r += htmltext('<div class="section form-inner-container">')
r += form.render()
r += htmltext('</div>')
return r.getvalue()
else:
reason = None