admin: factor "last modification block" code (#43564)

This commit is contained in:
Frédéric Péters 2020-06-03 11:14:58 +02:00
parent 6381b9f5f5
commit ae87205dec
4 changed files with 54 additions and 54 deletions

View File

@ -44,6 +44,7 @@ from wcs.roles import Role, logged_users_role, get_user_roles
from wcs.workflows import Workflow
from wcs.forms.root import qrcode
from . import utils
from .fields import FieldDefPage, FieldsDirectory
from .categories import CategoriesDirectory
from .data_sources import NamedDataSourcesDirectory
@ -402,24 +403,7 @@ class FormDefPage(Directory):
r += htmltext('</span>')
r += htmltext('</div>')
if self.formdef.last_modification_time:
warning_class = ''
if (time.time() - time.mktime(self.formdef.last_modification_time)) < 600:
if get_request().user and str(get_request().user.id) != self.formdef.last_modification_user_id:
warning_class = 'recent'
r += htmltext('<p class="last-modification %s">') % warning_class
r += _('Last Modification:')
r += ' '
r += misc.localstrftime(self.formdef.last_modification_time)
r += ' '
if self.formdef.last_modification_user_id:
try:
r += _('by %s') % get_publisher().user_class.get(
self.formdef.last_modification_user_id).display_name
except KeyError:
pass
r += htmltext('</p>')
r += utils.last_modification_block(obj=self.formdef)
r += get_session().display_message()
def add_option_line(link, label, current_value):

47
wcs/admin/utils.py Normal file
View File

@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
#
# w.c.s. - web application for online forms
# Copyright (C) 2005-2010 Entr'ouvert
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
import time
from quixote import get_publisher, get_request
from quixote.html import TemplateIO, htmltext
from qommon import _, misc
def last_modification_block(obj):
r = TemplateIO(html=True)
if obj.last_modification_time:
warning_class = ''
if (time.time() - time.mktime(obj.last_modification_time)) < 600:
if get_request().user and str(get_request().user.id) != obj.last_modification_user_id:
warning_class = 'recent'
r += htmltext('<p class="last-modification %s">') % warning_class
r += _('Last Modification:')
r += ' '
r += misc.localstrftime(obj.last_modification_time)
r += ' '
if obj.last_modification_user_id:
try:
r += _('by %s') % get_publisher().user_class.get(
obj.last_modification_user_id).display_name
except KeyError:
pass
r += htmltext('</p>')
return r.getvalue()

View File

@ -43,6 +43,8 @@ from wcs.workflows import *
from wcs.carddef import CardDef
from wcs.formdef import FormDef
from wcs.formdata import Evolution
from . import utils
from .fields import FieldDefPage, FieldsDirectory
from .data_sources import NamedDataSourcesDirectory
from .logged_errors import LoggedErrorsDirectory
@ -1389,24 +1391,7 @@ class WorkflowPage(Directory):
r += htmltext('</span>')
r += htmltext('</div>')
if self.workflow.last_modification_time:
warning_class = ''
if (time.time() - time.mktime(self.workflow.last_modification_time)) < 600:
if get_request().user and str(get_request().user.id) != self.workflow.last_modification_user_id:
warning_class = 'recent'
r += htmltext('<p class="last-modification %s">') % warning_class
r += _('Last Modification:')
r += ' '
r += misc.localstrftime(self.workflow.last_modification_time)
r += ' '
if self.workflow.last_modification_user_id:
try:
r += _('by %s') % get_publisher().user_class.get(
self.workflow.last_modification_user_id).display_name
except KeyError:
pass
r += htmltext('</p>')
r += utils.last_modification_block(obj=self.workflow)
r += get_session().display_message()
r += htmltext('<div class="splitcontent-left">')

View File

@ -30,6 +30,7 @@ from wcs.roles import Role
from wcs.workflows import Workflow
from wcs.admin.forms import FormsDirectory, FormDefPage, FormDefUI, html_top
from wcs.admin.logged_errors import LoggedErrorsDirectory
from wcs.admin import utils
class CardDefUI(FormDefUI):
@ -70,24 +71,7 @@ class CardDefPage(FormDefPage):
r += htmltext('</span>')
r += htmltext('</div>')
if self.formdef.last_modification_time:
warning_class = ''
if (time.time() - time.mktime(self.formdef.last_modification_time)) < 600:
if get_request().user and str(get_request().user.id) != self.formdef.last_modification_user_id:
warning_class = 'recent'
r += htmltext('<p class="last-modification %s">') % warning_class
r += _('Last Modification:')
r += ' '
r += misc.localstrftime(self.formdef.last_modification_time)
r += ' '
if self.formdef.last_modification_user_id:
try:
r += _('by %s') % get_publisher().user_class.get(
self.formdef.last_modification_user_id).display_name
except KeyError:
pass
r += htmltext('</p>')
r += utils.last_modification_block(obj=self.formdef)
r += get_session().display_message()
def add_option_line(link, label, current_value):