|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# |
|
3
|
|
|
# This file is part of SENAITE.CORE |
|
4
|
|
|
# |
|
5
|
|
|
# Copyright 2018 by it's authors. |
|
6
|
|
|
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst. |
|
7
|
|
|
|
|
8
|
|
|
from AccessControl import ClassSecurityInfo |
|
9
|
|
|
from Products.Archetypes.Registry import registerPropertyType |
|
10
|
|
|
from Products.Archetypes.Registry import registerWidget |
|
11
|
|
|
from Products.Archetypes.Widget import TypesWidget |
|
12
|
|
|
from bika.lims.browser import get_date |
|
13
|
|
|
from bika.lims.browser import ulocalized_time as ut |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
class DateTimeWidget(TypesWidget): |
|
17
|
|
|
_properties = TypesWidget._properties.copy() |
|
18
|
|
|
_properties.update({ |
|
19
|
|
|
'show_time': False, |
|
20
|
|
|
'macro': "bika_widgets/datetimewidget", |
|
21
|
|
|
'helper_js': ("bika_widgets/datetimewidget.js",), |
|
22
|
|
|
'helper_css': ("bika_widgets/datetimewidget.css",), |
|
23
|
|
|
}) |
|
24
|
|
|
|
|
25
|
|
|
security = ClassSecurityInfo() |
|
26
|
|
|
|
|
27
|
|
|
def ulocalized_time(self, time, context, request): |
|
28
|
|
|
"""Returns the localized time in string format |
|
29
|
|
|
""" |
|
30
|
|
|
value = ut(time, long_format=self.show_time, time_only=False, |
|
31
|
|
|
context=context, request=request) |
|
32
|
|
|
return value or "" |
|
33
|
|
|
|
|
34
|
|
|
def ulocalized_gmt0_time(self, time, context, request): |
|
35
|
|
|
"""Returns the localized time in string format, but in GMT+0 |
|
36
|
|
|
""" |
|
37
|
|
|
value = get_date(context, time) |
|
38
|
|
|
if not value: |
|
39
|
|
|
return "" |
|
40
|
|
|
# DateTime is stored with TimeZone, but DateTimeWidget omits TZ |
|
41
|
|
|
value = value.toZone("GMT+0") |
|
42
|
|
|
return self.ulocalized_time(value, context, request) |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
registerWidget( |
|
46
|
|
|
DateTimeWidget, |
|
47
|
|
|
title='DateTimeWidget', |
|
48
|
|
|
description=('Simple text field, with a jquery date widget attached.') |
|
49
|
|
|
) |
|
50
|
|
|
|
|
51
|
|
|
registerPropertyType('show_time', 'boolean') |
|
52
|
|
|
|