84 lines
3.2 KiB
Python
84 lines
3.2 KiB
Python
# -*- 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 wcs.qommon import _
|
|
from wcs.qommon.misc import localstrftime
|
|
|
|
|
|
def last_modification_block(obj):
|
|
r = TemplateIO(html=True)
|
|
|
|
timestamp, user_id = obj.get_last_modification_info()
|
|
if timestamp:
|
|
warning_class = ''
|
|
if (time.time() - timestamp.timestamp()) < 600:
|
|
if get_request().user and str(get_request().user.id) != user_id:
|
|
warning_class = 'recent'
|
|
r += htmltext('<p class="last-modification %s">') % warning_class
|
|
r += _('Last Modification:')
|
|
r += ' '
|
|
r += localstrftime(timestamp)
|
|
r += ' '
|
|
if user_id:
|
|
try:
|
|
r += _('by %s') % get_publisher().user_class.get(user_id).display_name
|
|
except KeyError:
|
|
pass
|
|
r += htmltext('</p>')
|
|
|
|
return r.getvalue()
|
|
|
|
|
|
def snapshot_info_block(snapshot):
|
|
r = TemplateIO(html=True)
|
|
r += htmltext('<p>')
|
|
parts = []
|
|
if snapshot.label:
|
|
parts.append(htmltext('<strong>%s</strong>') % snapshot.label)
|
|
elif snapshot.comment:
|
|
parts.append(snapshot.comment)
|
|
if snapshot.user_id:
|
|
parts.append('%s (%s)' % (localstrftime(snapshot.timestamp), snapshot.user))
|
|
else:
|
|
parts.append(localstrftime(snapshot.timestamp))
|
|
r += htmltext('<br />').join(parts)
|
|
r += htmltext('</p>')
|
|
if snapshot.previous or snapshot.next:
|
|
r += htmltext('<p class="snapshots-navigation">')
|
|
if snapshot.id != snapshot.first:
|
|
r += htmltext(' <a class="button" href="../../%s/view/">≪</a>' % (snapshot.first))
|
|
r += htmltext(' <a class="button" href="../../%s/view/"><</a>' % (snapshot.previous))
|
|
else:
|
|
# currently browsing the first snapshot, display links as disabled
|
|
r += htmltext(' <a class="button disabled" href="#">≪</a>')
|
|
r += htmltext(' <a class="button disabled" href="#"><</a>')
|
|
if snapshot.id != snapshot.last:
|
|
r += htmltext(' <a class="button" href="../../%s/view/">></a>' % (snapshot.next))
|
|
r += htmltext(' <a class="button" href="../../%s/view/">≫</a>' % (snapshot.last))
|
|
else:
|
|
# currently browsing the last snapshot, display links as disabled
|
|
r += htmltext(' <a class="button disabled" href="#">></a>')
|
|
r += htmltext(' <a class="button disabled" href="#">≫</a>')
|
|
r += htmltext('</p>')
|
|
return r.getvalue()
|