Passed
Push — master ( b77d42...61afd1 )
by Ramon
05:36
created

DateTimeField.set()   A

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nop 4
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()
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable Field does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
Undefined variable 'Field'
Loading history...
26
    _properties.update({
27
        'type': 'datetime',
28
        'widget': CalendarWidget,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable CalendarWidget does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
Undefined variable 'CalendarWidget'
Loading history...
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