Projet

Général

Profil

0001-admin-use-new-option-style-for-options-classifying-f.patch

Frédéric Péters, 14 août 2015 11:44

Télécharger (9,41 ko)

Voir les différences:

Subject: [PATCH 1/4] admin: use new option style for options classifying forms
 (#8049)

This is about description, keywords, and categories.
 tests/test_admin_pages.py |  12 +++---
 wcs/admin/forms.py        | 106 ++++++++++++++++++++--------------------------
 2 files changed, 52 insertions(+), 66 deletions(-)
tests/test_admin_pages.py
295 295

  
296 296
    app = login(get_app(pub))
297 297
    resp = app.get('/backoffice/forms/1/')
298
    assert 'Category:' not in resp.body
298
    assert_option_display(resp, 'Category', 'None')
299 299

  
300 300
    Category.wipe()
301 301
    cat = Category(name='Foo')
......
303 303
    cat = Category(name='Bar')
304 304
    cat.store()
305 305
    resp = app.get('/backoffice/forms/1/')
306
    assert 'Category:' in resp.body
306
    assert 'Category' in resp.body
307
    assert_option_display(resp, 'Category', 'None')
307 308

  
308 309
def test_form_category_select():
309 310
    create_superuser()
......
697 698

  
698 699
    app = login(get_app(pub))
699 700
    resp = app.get('/backoffice/forms/1/')
700
    assert 'No description or keywords' in resp.body
701
    assert_option_display(resp, 'Description', 'None')
701 702

  
702
    resp = resp.click(href='information')
703
    resp = resp.click('Description')
703 704
    resp.forms[0]['description'].value = '<p>Hello World</p>'
704 705
    resp = resp.forms[0].submit()
705 706
    assert resp.location == 'http://example.net/backoffice/forms/1/'
706 707
    resp = resp.follow()
707
    assert 'No description or keywords' not in resp.body
708
    assert 'Hello World' in resp.body
708
    assert_option_display(resp, 'Description', 'On')
709 709

  
710 710
def test_form_new_field():
711 711
    create_superuser()
wcs/admin/forms.py
132 132

  
133 133
class OptionsDirectory(Directory):
134 134
    _q_exports = ['confirmation', 'private_status', 'only_allow_one',
135
            'always_advertise', 'tracking_code', 'online_status']
135
            'always_advertise', 'tracking_code', 'online_status',
136
            'description', 'keywords', 'category']
136 137

  
137 138
    def __init__(self, formdef):
138 139
        self.formdef = formdef
......
190 191
                 value=self.formdef.expiration_date)
191 192
        return self.handle(form, _('Online Status'))
192 193

  
194
    def description(self):
195
        form = Form(enctype='multipart/form-data')
196
        form.add(WysiwygTextWidget, 'description', title=_('Description'),
197
                value=self.formdef.description)
198
        return self.handle(form, _('Description'))
199

  
200
    def keywords(self):
201
        form = Form(enctype='multipart/form-data')
202
        form.add(StringWidget, 'keywords', title=_('Keywords'),
203
                value=self.formdef.keywords, size=50)
204
        return self.handle(form, _('Keywords'))
205

  
206
    def category(self):
207
        categories = get_categories()
208
        form = Form(enctype='multipart/form-data')
209
        form.widgets.append(HtmlWidget('<p>%s</p>' % _('Select a category for this form')))
210
        form.add(SingleSelectWidget, 'category_id', title=_('Category'),
211
               value=self.formdef.category_id,
212
               options=[(None, '---', '')] + categories)
213
        return self.handle(form, _('Category'))
214

  
193 215
    def handle(self, form, title):
194 216
        form.add_submit('submit', _('Submit'))
195 217
        form.add_submit('cancel', _('Cancel'))
......
200 222
            attrs = ['confirmation', 'only_allow_one', 'disabled',
201 223
                    'enable_tracking_codes', 'private_status_and_history',
202 224
                    'always_advertise', 'disabled_redirection',
203
                    'publication_date', 'expiration_date']
225
                    'publication_date', 'expiration_date', 'description',
226
                    'keywords', 'category_id']
204 227
            for f in attrs:
205 228
                widget = form.get_widget(f)
206 229
                if widget:
......
255 278
class FormDefPage(Directory):
256 279
    _q_exports = ['', 'fields', 'delete', 'duplicate', 'export',
257 280
                  'anonymise', 'archive', 'invite', 'enable', 'workflow',
258
                  'category', 'role', ('workflow-options', 'workflow_options'),
281
                  'role', ('workflow-options', 'workflow_options'),
259 282
                  ('workflow-variables', 'workflow_variables'),
260 283
                  ('workflow-status-remapping', 'workflow_status_remapping'),
261 284
                  'roles', 'title', 'options', ('acl-read', 'acl_read'),
......
312 335

  
313 336
        r += get_session().display_message()
314 337

  
338
        def add_option_line(link, label, current_value):
339
            return htmltext(
340
                    '<li><a rel="popup" href="%(link)s">'
341
                    '<span class="label">%(label)s</span> '
342
                    '<span class="value">%(current_value)s</span>'
343
                    '</a></li>' % {
344
                              'link': link,
345
                              'label': label,
346
                              'current_value': current_value})
347

  
315 348
        r += htmltext('<div class="bo-block">')
316
        r += htmltext('<h3>%s') % _('Information')
317
        if not (self.formdef.description or self.formdef.keywords):
318
            r += htmltext(' <span class="change">(%s)</span>') % _('No description or keywords')
319
        r += htmltext(' <span class="change">(<a rel="popup" href="information">%s</a>)</span></h3>') % _('change')
320
        if self.formdef.description:
321
            r += htmltext(self.formdef.description)
322
        if self.formdef.keywords:
323
            r += htmltext('<p>%s %s</p>') % (
324
                    _('Keywords:'), self.formdef.keywords)
349
        r += htmltext('<h3>%s</h3>') % _('Information')
350
        r += htmltext('<ul class="biglist optionslist">')
351

  
352
        r += add_option_line('options/description', _('Description'),
353
                self.formdef.description and _('On') or _('None'))
354
        r += add_option_line('options/keywords', _('Keywords'),
355
                self.formdef.keywords and self.formdef.keywords or _('None'))
356
        r += add_option_line('options/category', _('Category'),
357
                self.formdef.category_id and self.formdef.category.name or _('None'))
358
        r += htmltext('</ul>')
325 359
        r += htmltext('</div>')
326 360

  
327 361
        r += htmltext('<div class="splitcontent-left">')
......
329 363
        r += htmltext('<h3>%s</h3>') % _('Access')
330 364
        r += htmltext('<ul>')
331 365

  
332
        categories = get_categories()
333
        if categories:
334
            r += htmltext('<li>%s ') % _('Category:')
335
            if self.formdef.category:
336
                r += self.formdef.category.name
337
            else:
338
                r += '-'
339
            r += ' '
340
            r += htmltext('(<a href="category" rel="popup">%s</a>)') % _('change')
341
            r += htmltext('</li>')
342

  
343 366
        workflows = get_workflows()
344 367
        if workflows:
345 368
            r += htmltext('<li>%s ') % _('Workflow:')
......
407 430
        r += htmltext('<h3>%s</h3>') % _('Options')
408 431
        r += htmltext('<ul class="biglist optionslist">')
409 432

  
410
        def add_option_line(link, label, current_value):
411
            return htmltext(
412
                    '<li><a rel="popup" href="%(link)s">'
413
                    '<span class="label">%(label)s</span> '
414
                    '<span class="value">%(current_value)s</span>'
415
                    '</a></li>' % {
416
                              'link': link,
417
                              'label': label,
418
                              'current_value': current_value})
419

  
420 433
        r += add_option_line('options/confirmation', _('Confirmation Page'),
421 434
            self.formdef.confirmation and _('Enabled') or _('Disabled'))
422 435

  
......
662 675
        r += form.render()
663 676
        return r.getvalue()
664 677

  
665
    def information(self):
666
        form = Form(enctype='multipart/form-data')
667
        form.add(WysiwygTextWidget, 'description', title=_('Description'),
668
                value=self.formdef.description)
669
        form.add(StringWidget, 'keywords', title=_('Keywords'),
670
                value=self.formdef.keywords, size=50)
671

  
672
        form.add_submit('submit', _('Submit'))
673
        form.add_submit('cancel', _('Cancel'))
674
        if form.get_widget('cancel').parse():
675
            return redirect('.')
676

  
677
        if form.is_submitted() and not form.has_errors():
678
            for field_name in ('description', 'keywords'):
679
                widget = form.get_widget(field_name)
680
                if widget:
681
                    setattr(self.formdef, field_name, widget.parse())
682
            self.formdef.store()
683
            return redirect('.')
684

  
685
        get_response().breadcrumb.append( ('information', _('Information')) )
686
        self.html_top(title=self.formdef.name)
687
        r = TemplateIO(html=True)
688
        r += htmltext('<h2>%s</h2>') % _('Information')
689
        r += form.render()
690
        return r.getvalue()
691

  
692 678
    def workflow(self):
693 679
        form = Form(enctype='multipart/form-data')
694 680
        workflows = get_workflows(condition=lambda x: x.possible_status)
695
-