|
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 registerField |
|
10
|
|
|
from Products.Archetypes.interfaces import IDateTimeField |
|
11
|
|
|
from Products.Archetypes.public import * |
|
12
|
|
|
from Products.Archetypes.public import DateTimeField as DTF |
|
13
|
|
|
from bika.lims.browser import get_date |
|
14
|
|
|
from zope.interface import implements |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
class DateTimeField(DTF): |
|
18
|
|
|
"""A field that stores dates and times |
|
19
|
|
|
This is identical to the AT widget on which it's based, but it checks |
|
20
|
|
|
the i18n translation values for date formats. This does not specifically |
|
21
|
|
|
check the date_format_short_datepicker, so this means that date_formats |
|
22
|
|
|
should be identical between the python strftime and the jquery version. |
|
23
|
|
|
""" |
|
24
|
|
|
|
|
25
|
|
|
_properties = Field._properties.copy() |
|
|
|
|
|
|
26
|
|
|
_properties.update({ |
|
27
|
|
|
'type': 'datetime', |
|
28
|
|
|
'widget': CalendarWidget, |
|
|
|
|
|
|
29
|
|
|
}) |
|
30
|
|
|
|
|
31
|
|
|
implements(IDateTimeField) |
|
32
|
|
|
|
|
33
|
|
|
security = ClassSecurityInfo() |
|
34
|
|
|
|
|
35
|
|
|
security.declarePrivate('set') |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
def set(self, instance, value, **kwargs): |
|
39
|
|
|
""" |
|
40
|
|
|
Check if value is an actual date/time value. If not, attempt |
|
41
|
|
|
to convert it to one; otherwise, set to None. Assign all |
|
42
|
|
|
properties passed as kwargs to object. |
|
43
|
|
|
""" |
|
44
|
|
|
val = get_date(instance, value) |
|
45
|
|
|
super(DateTimeField, self).set(instance, val, **kwargs) |
|
46
|
|
|
|
|
47
|
|
|
registerField(DateTimeField, |
|
48
|
|
|
title='Date Time', |
|
49
|
|
|
description='Used for storing date/time') |
|
50
|
|
|
|