backoffice: include "empty site" message in classic forms view (#21949)

This commit is contained in:
Frédéric Péters 2018-02-18 14:39:18 +01:00
parent ba5936593e
commit da19af24c8
2 changed files with 18 additions and 12 deletions

View File

@ -2465,7 +2465,7 @@ def test_global_listing(pub):
assert not 'form-title' in resp.body
def test_global_listing_with_no_formdefs(pub):
def test_management_views_with_no_formdefs(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
return
@ -2481,8 +2481,9 @@ def test_global_listing_with_no_formdefs(pub):
cur.close()
app = login(get_app(pub))
resp = app.get('/backoffice/management/').follow()
resp = resp.click('Global View')
resp = app.get('/backoffice/management/forms')
assert 'This site is currently empty.' in resp.body
resp = app.get('/backoffice/management/listing')
assert 'This site is currently empty.' in resp.body
def test_category_in_global_listing(pub):

View File

@ -451,6 +451,8 @@ class ManagementDirectory(Directory):
def forms(self):
html_top('management', _('Management'))
formdefs = FormDef.select(order_by='name', ignore_errors=True)
if len(formdefs) == 0:
return self.empty_site_message(_('Forms'))
get_response().filter['sidebar'] = self.get_sidebar(formdefs)
r = TemplateIO(html=True)
r += get_session().display_message()
@ -773,6 +775,17 @@ class ManagementDirectory(Directory):
criterias.append(FtsMatch(get_request().form.get('q')))
return criterias
def empty_site_message(self, title):
r = TemplateIO(html=True)
r += htmltext('<div class="top-title">')
r += htmltext('<h2>%s</h2>') % title
r += htmltext('</div>')
r += htmltext('<div class="big-msg-info">')
r += htmltext('<p>%s</p>') % _(
'This site is currently empty. It is required to first add forms.')
r += htmltext('</div>')
return r.getvalue()
def listing(self):
if not get_publisher().is_using_postgresql():
raise errors.TraversalError()
@ -782,15 +795,7 @@ class ManagementDirectory(Directory):
html_top('management', _('Management'))
if FormDef.count() == 0:
r = TemplateIO(html=True)
r += htmltext('<div class="top-title">')
r += htmltext('<h2>%s</h2>') % _('Global View')
r += htmltext('</div>')
r += htmltext('<div class="big-msg-info">')
r += htmltext('<p>%s</p>') % _(
'This site is currently empty. It is required to first add forms.')
r += htmltext('</div>')
return r.getvalue()
return self.empty_site_message(_('Global View'))
limit = int(get_request().form.get('limit',
get_publisher().get_site_option('default-page-size') or 20))