Projet

Général

Profil

0001-backoffice-add-channel-and-modification-time-columns.patch

Frédéric Péters, 08 novembre 2015 21:52

Télécharger (5,34 ko)

Voir les différences:

Subject: [PATCH] backoffice: add channel and modification time columns to
 global listing (#8918)

 tests/test_backoffice_pages.py | 21 +++++++++++++++++++++
 wcs/backoffice/management.py   | 13 +++++++++++--
 wcs/formdata.py                |  7 ++++++-
 wcs/sql.py                     |  1 +
 4 files changed, 39 insertions(+), 3 deletions(-)
tests/test_backoffice_pages.py
4 4
import re
5 5
import shutil
6 6
import StringIO
7
import time
7 8

  
8 9
import pytest
9 10

  
......
920 921
    assert 'http://example.net/backoffice/management/other-form/' in resp.body
921 922
    assert not 'http://example.net/backoffice/management/form-title/' in resp.body
922 923

  
924
    formdef = FormDef.get_by_urlname('form-title')
925
    last_update_time = formdef.data_class().select()[0].last_update_time
926
    # check created and last modified columns
927
    assert '>2014-01-01 00:00<' in resp.body
928
    assert time.strftime('>%Y-%m-%d', last_update_time) in resp.body
929

  
930
    # check a Channel column is added when welco is available
931
    assert not 'Channel' in resp.body
932

  
933
    if not pub.site_options.has_section('variables'):
934
        pub.site_options.add_section('variables')
935
    pub.site_options.set('variables', 'welco_url', 'xxx')
936
    fd = open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w')
937
    pub.site_options.write(fd)
938
    fd.close()
939

  
940
    resp = app.get('/backoffice/management/listing')
941
    assert 'Channel' in resp.body
942
    assert '>Web<' in resp.body
943

  
923 944
def test_tracking_code_access(pub):
924 945
    create_user(pub)
925 946
    create_environment(pub, set_receiver=False)
wcs/backoffice/management.py
337 337
        total_count = sql.AnyFormData.count(criterias)
338 338
        formdatas = sql.AnyFormData.select(criterias,
339 339
                order_by='receipt_time', limit=limit, offset=offset)
340
        include_submission_channel = bool(
341
                get_publisher().get_site_option('welco_url', 'variables'))
340 342

  
341 343
        r = TemplateIO(html=True)
342 344
        r += htmltext('<table id="listing" class="main">')
343 345
        r += htmltext('<thead>')
346
        if include_submission_channel:
347
            r += htmltext('<th>%s</th>') % _('Channel')
344 348
        r += htmltext('<th>%s</th>') % _('Form')
345
        r += htmltext('<th>%s</th>') % _('Date')
349
        r += htmltext('<th>%s</th>') % _('Created')
350
        r += htmltext('<th>%s</th>') % _('Last Modified')
346 351
        r += htmltext('<th>%s</th>') % _('User')
347 352
        r += htmltext('<th>%s</th>') % _('Status')
348 353
        r += htmltext('</thead>')
......
355 360
                    formdata.formdef.workflow.id,
356 361
                    formdata.status,
357 362
                    formdata.get_url(backoffice=True)))
363
            if include_submission_channel:
364
                r += htmltext('<td>%s</td>') % formdata.get_submission_channel_label()
358 365
            r += htmltext('<td>%s</td>') % formdata.formdef.name
359 366
            r += htmltext('<td class="cell-time">%s</td>') % misc.localstrftime(
360 367
                    formdata.receipt_time)
368
            r += htmltext('<td class="cell-time">%s</td>') % misc.localstrftime(
369
                    formdata.last_update_time)
361 370
            try:
362 371
                value = get_publisher().user_class.get(formdata.user_id).display_name
363 372
                r += htmltext('<td class="cell-user">%s</td>') % value
364 373
            except:
365 374
                r += htmltext('<td class="cell-user cell-no-user">-</td>')
366 375
            r += htmltext('<td class="cell-status">%s</td>') % formdata.get_status_label()
367
            r += htmltext('</tr>')
376
            r += htmltext('</tr>\n')
368 377

  
369 378
        if workflows:
370 379
            colours = []
wcs/formdata.py
556 556
    actions_roles = property(get_actions_roles)
557 557

  
558 558
    def get_last_update_time(self):
559
        if hasattr(self, '_last_update_time'):
560
            return self._last_update_time
559 561
        if self.evolution and self.evolution[-1].time:
560 562
            return self.evolution[-1].time
561 563
        else:
562 564
            return self.receipt_time
563 565

  
564
    last_update_time = property(get_last_update_time)
566
    def set_last_update_time(self, value):
567
        self._last_update_time = value
568

  
569
    last_update_time = property(get_last_update_time, set_last_update_time)
565 570

  
566 571
    def anonymise(self):
567 572
        for field in self.formdef.fields:
wcs/sql.py
1535 1535
        fake_formdef = FormDef()
1536 1536
        common_fields = get_view_fields(fake_formdef)
1537 1537
        cls.__table_static_fields = [(x[1], x[0]) for x in common_fields]
1538
        cls.__table_static_fields.append(('last_update_time', 'timestamp'))
1538 1539
        return cls.__table_static_fields
1539 1540

  
1540 1541
    @classmethod
1541
-