Projet

Général

Profil

0001-admin-factor-last-modification-block-code-43564.patch

Frédéric Péters, 03 juin 2020 11:19

Télécharger (7,31 ko)

Voir les différences:

Subject: [PATCH] admin: factor "last modification block" code (#43564)

 wcs/admin/forms.py      | 20 ++----------------
 wcs/admin/utils.py      | 47 +++++++++++++++++++++++++++++++++++++++++
 wcs/admin/workflows.py  | 21 +++---------------
 wcs/backoffice/cards.py | 20 ++----------------
 4 files changed, 54 insertions(+), 54 deletions(-)
 create mode 100644 wcs/admin/utils.py
wcs/admin/forms.py
44 44
from wcs.workflows import Workflow
45 45
from wcs.forms.root import qrcode
46 46

  
47
from . import utils
47 48
from .fields import FieldDefPage, FieldsDirectory
48 49
from .categories import CategoriesDirectory
49 50
from .data_sources import NamedDataSourcesDirectory
......
402 403
        r += htmltext('</span>')
403 404
        r += htmltext('</div>')
404 405

  
405
        if self.formdef.last_modification_time:
406
            warning_class = ''
407
            if (time.time() - time.mktime(self.formdef.last_modification_time)) < 600:
408
                if get_request().user and str(get_request().user.id) != self.formdef.last_modification_user_id:
409
                    warning_class = 'recent'
410
            r += htmltext('<p class="last-modification %s">') % warning_class
411
            r += _('Last Modification:')
412
            r += ' '
413
            r += misc.localstrftime(self.formdef.last_modification_time)
414
            r += ' '
415
            if self.formdef.last_modification_user_id:
416
                try:
417
                    r += _('by %s') % get_publisher().user_class.get(
418
                                    self.formdef.last_modification_user_id).display_name
419
                except KeyError:
420
                    pass
421
            r += htmltext('</p>')
422

  
406
        r += utils.last_modification_block(obj=self.formdef)
423 407
        r += get_session().display_message()
424 408

  
425 409
        def add_option_line(link, label, current_value):
wcs/admin/utils.py
1
# -*- coding: utf-8 -*-
2
#
3
# w.c.s. - web application for online forms
4
# Copyright (C) 2005-2010  Entr'ouvert
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, see <http://www.gnu.org/licenses/>.
18

  
19
import time
20

  
21
from quixote import get_publisher, get_request
22
from quixote.html import TemplateIO, htmltext
23

  
24
from qommon import _, misc
25

  
26

  
27
def last_modification_block(obj):
28
    r = TemplateIO(html=True)
29
    if obj.last_modification_time:
30
        warning_class = ''
31
        if (time.time() - time.mktime(obj.last_modification_time)) < 600:
32
            if get_request().user and str(get_request().user.id) != obj.last_modification_user_id:
33
                warning_class = 'recent'
34
        r += htmltext('<p class="last-modification %s">') % warning_class
35
        r += _('Last Modification:')
36
        r += ' '
37
        r += misc.localstrftime(obj.last_modification_time)
38
        r += ' '
39
        if obj.last_modification_user_id:
40
            try:
41
                r += _('by %s') % get_publisher().user_class.get(
42
                                obj.last_modification_user_id).display_name
43
            except KeyError:
44
                pass
45
        r += htmltext('</p>')
46

  
47
    return r.getvalue()
wcs/admin/workflows.py
43 43
from wcs.carddef import CardDef
44 44
from wcs.formdef import FormDef
45 45
from wcs.formdata import Evolution
46

  
47
from . import utils
46 48
from .fields import FieldDefPage, FieldsDirectory
47 49
from .data_sources import NamedDataSourcesDirectory
48 50
from .logged_errors import LoggedErrorsDirectory
......
1389 1391
            r += htmltext('</span>')
1390 1392
        r += htmltext('</div>')
1391 1393

  
1392
        if self.workflow.last_modification_time:
1393
            warning_class = ''
1394
            if (time.time() - time.mktime(self.workflow.last_modification_time)) < 600:
1395
                if get_request().user and str(get_request().user.id) != self.workflow.last_modification_user_id:
1396
                    warning_class = 'recent'
1397
            r += htmltext('<p class="last-modification %s">') % warning_class
1398
            r += _('Last Modification:')
1399
            r += ' '
1400
            r += misc.localstrftime(self.workflow.last_modification_time)
1401
            r += ' '
1402
            if self.workflow.last_modification_user_id:
1403
                try:
1404
                    r += _('by %s') % get_publisher().user_class.get(
1405
                                    self.workflow.last_modification_user_id).display_name
1406
                except KeyError:
1407
                    pass
1408
            r += htmltext('</p>')
1409

  
1394
        r += utils.last_modification_block(obj=self.workflow)
1410 1395
        r += get_session().display_message()
1411 1396

  
1412 1397
        r += htmltext('<div class="splitcontent-left">')
wcs/backoffice/cards.py
30 30
from wcs.workflows import Workflow
31 31
from wcs.admin.forms import FormsDirectory, FormDefPage, FormDefUI, html_top
32 32
from wcs.admin.logged_errors import LoggedErrorsDirectory
33
from wcs.admin import utils
33 34

  
34 35

  
35 36
class CardDefUI(FormDefUI):
......
70 71
        r += htmltext('</span>')
71 72
        r += htmltext('</div>')
72 73

  
73
        if self.formdef.last_modification_time:
74
            warning_class = ''
75
            if (time.time() - time.mktime(self.formdef.last_modification_time)) < 600:
76
                if get_request().user and str(get_request().user.id) != self.formdef.last_modification_user_id:
77
                    warning_class = 'recent'
78
            r += htmltext('<p class="last-modification %s">') % warning_class
79
            r += _('Last Modification:')
80
            r += ' '
81
            r += misc.localstrftime(self.formdef.last_modification_time)
82
            r += ' '
83
            if self.formdef.last_modification_user_id:
84
                try:
85
                    r += _('by %s') % get_publisher().user_class.get(
86
                                    self.formdef.last_modification_user_id).display_name
87
                except KeyError:
88
                    pass
89
            r += htmltext('</p>')
90

  
74
        r += utils.last_modification_block(obj=self.formdef)
91 75
        r += get_session().display_message()
92 76

  
93 77
        def add_option_line(link, label, current_value):
94
-