admin: use new option style for options classifying forms (#8049)

This is about description, keywords, and categories.
This commit is contained in:
Frédéric Péters 2015-08-06 14:11:46 +02:00
parent 70d72878a0
commit 2adfe9d67b
2 changed files with 52 additions and 66 deletions

View File

@ -306,7 +306,7 @@ def test_form_category():
app = login(get_app(pub))
resp = app.get('/backoffice/forms/1/')
assert 'Category:' not in resp.body
assert_option_display(resp, 'Category', 'None')
Category.wipe()
cat = Category(name='Foo')
@ -314,7 +314,8 @@ def test_form_category():
cat = Category(name='Bar')
cat.store()
resp = app.get('/backoffice/forms/1/')
assert 'Category:' in resp.body
assert 'Category' in resp.body
assert_option_display(resp, 'Category', 'None')
def test_form_category_select():
create_superuser()
@ -708,15 +709,14 @@ def test_form_description():
app = login(get_app(pub))
resp = app.get('/backoffice/forms/1/')
assert 'No description or keywords' in resp.body
assert_option_display(resp, 'Description', 'None')
resp = resp.click(href='information')
resp = resp.click('Description')
resp.forms[0]['description'].value = '<p>Hello World</p>'
resp = resp.forms[0].submit()
assert resp.location == 'http://example.net/backoffice/forms/1/'
resp = resp.follow()
assert 'No description or keywords' not in resp.body
assert 'Hello World' in resp.body
assert_option_display(resp, 'Description', 'On')
def test_form_new_field():
create_superuser()

View File

@ -132,7 +132,8 @@ class FieldsDirectory(FieldsDirectory):
class OptionsDirectory(Directory):
_q_exports = ['confirmation', 'private_status', 'only_allow_one',
'always_advertise', 'tracking_code', 'online_status', 'captcha']
'always_advertise', 'tracking_code', 'online_status', 'captcha',
'description', 'keywords', 'category']
def __init__(self, formdef):
self.formdef = formdef
@ -197,6 +198,27 @@ class OptionsDirectory(Directory):
value=self.formdef.expiration_date)
return self.handle(form, _('Online Status'))
def description(self):
form = Form(enctype='multipart/form-data')
form.add(WysiwygTextWidget, 'description', title=_('Description'),
value=self.formdef.description)
return self.handle(form, _('Description'))
def keywords(self):
form = Form(enctype='multipart/form-data')
form.add(StringWidget, 'keywords', title=_('Keywords'),
value=self.formdef.keywords, size=50)
return self.handle(form, _('Keywords'))
def category(self):
categories = get_categories()
form = Form(enctype='multipart/form-data')
form.widgets.append(HtmlWidget('<p>%s</p>' % _('Select a category for this form')))
form.add(SingleSelectWidget, 'category_id', title=_('Category'),
value=self.formdef.category_id,
options=[(None, '---', '')] + categories)
return self.handle(form, _('Category'))
def handle(self, form, title):
form.add_submit('submit', _('Submit'))
form.add_submit('cancel', _('Cancel'))
@ -207,7 +229,8 @@ class OptionsDirectory(Directory):
attrs = ['confirmation', 'only_allow_one', 'disabled',
'enable_tracking_codes', 'private_status_and_history',
'always_advertise', 'disabled_redirection',
'publication_date', 'expiration_date', 'has_captcha']
'publication_date', 'expiration_date', 'has_captcha',
'description', 'keywords', 'category_id']
for f in attrs:
widget = form.get_widget(f)
if widget:
@ -262,7 +285,7 @@ class WorkflowRoleDirectory(Directory):
class FormDefPage(Directory):
_q_exports = ['', 'fields', 'delete', 'duplicate', 'export',
'anonymise', 'archive', 'invite', 'enable', 'workflow',
'category', 'role', ('workflow-options', 'workflow_options'),
'role', ('workflow-options', 'workflow_options'),
('workflow-variables', 'workflow_variables'),
('workflow-status-remapping', 'workflow_status_remapping'),
'roles', 'title', 'options', ('acl-read', 'acl_read'),
@ -319,16 +342,27 @@ class FormDefPage(Directory):
r += get_session().display_message()
def add_option_line(link, label, current_value):
return htmltext(
'<li><a rel="popup" href="%(link)s">'
'<span class="label">%(label)s</span> '
'<span class="value">%(current_value)s</span>'
'</a></li>' % {
'link': link,
'label': label,
'current_value': current_value})
r += htmltext('<div class="bo-block">')
r += htmltext('<h3>%s') % _('Information')
if not (self.formdef.description or self.formdef.keywords):
r += htmltext(' <span class="change">(%s)</span>') % _('No description or keywords')
r += htmltext(' <span class="change">(<a rel="popup" href="information">%s</a>)</span></h3>') % _('change')
if self.formdef.description:
r += htmltext(self.formdef.description)
if self.formdef.keywords:
r += htmltext('<p>%s %s</p>') % (
_('Keywords:'), self.formdef.keywords)
r += htmltext('<h3>%s</h3>') % _('Information')
r += htmltext('<ul class="biglist optionslist">')
r += add_option_line('options/description', _('Description'),
self.formdef.description and _('On') or _('None'))
r += add_option_line('options/keywords', _('Keywords'),
self.formdef.keywords and self.formdef.keywords or _('None'))
r += add_option_line('options/category', _('Category'),
self.formdef.category_id and self.formdef.category.name or _('None'))
r += htmltext('</ul>')
r += htmltext('</div>')
r += htmltext('<div class="splitcontent-left">')
@ -336,17 +370,6 @@ class FormDefPage(Directory):
r += htmltext('<h3>%s</h3>') % _('Access')
r += htmltext('<ul>')
categories = get_categories()
if categories:
r += htmltext('<li>%s ') % _('Category:')
if self.formdef.category:
r += self.formdef.category.name
else:
r += '-'
r += ' '
r += htmltext('(<a href="category" rel="popup">%s</a>)') % _('change')
r += htmltext('</li>')
workflows = get_workflows()
if workflows:
r += htmltext('<li>%s ') % _('Workflow:')
@ -414,16 +437,6 @@ class FormDefPage(Directory):
r += htmltext('<h3>%s</h3>') % _('Options')
r += htmltext('<ul class="biglist optionslist">')
def add_option_line(link, label, current_value):
return htmltext(
'<li><a rel="popup" href="%(link)s">'
'<span class="label">%(label)s</span> '
'<span class="value">%(current_value)s</span>'
'</a></li>' % {
'link': link,
'label': label,
'current_value': current_value})
r += add_option_line('options/confirmation', _('Confirmation Page'),
self.formdef.confirmation and _('Enabled') or _('Disabled'))
@ -673,33 +686,6 @@ class FormDefPage(Directory):
r += form.render()
return r.getvalue()
def information(self):
form = Form(enctype='multipart/form-data')
form.add(WysiwygTextWidget, 'description', title=_('Description'),
value=self.formdef.description)
form.add(StringWidget, 'keywords', title=_('Keywords'),
value=self.formdef.keywords, size=50)
form.add_submit('submit', _('Submit'))
form.add_submit('cancel', _('Cancel'))
if form.get_widget('cancel').parse():
return redirect('.')
if form.is_submitted() and not form.has_errors():
for field_name in ('description', 'keywords'):
widget = form.get_widget(field_name)
if widget:
setattr(self.formdef, field_name, widget.parse())
self.formdef.store()
return redirect('.')
get_response().breadcrumb.append( ('information', _('Information')) )
self.html_top(title=self.formdef.name)
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Information')
r += form.render()
return r.getvalue()
def workflow(self):
form = Form(enctype='multipart/form-data')
workflows = get_workflows(condition=lambda x: x.possible_status)