SplittedDateWidget.process_form()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nop 6
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.HEALTH.
4
#
5
# SENAITE.HEALTH is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by the Free
7
# Software Foundation, version 2.
8
#
9
# This program is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
# details.
13
#
14
# You should have received a copy of the GNU General Public License along with
15
# this program; if not, write to the Free Software Foundation, Inc., 51
16
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
#
18
# Copyright 2018-2019 by it's authors.
19
# Some rights reserved, see README and LICENSE.
20
21
from AccessControl import ClassSecurityInfo
22
from Products.Archetypes.Widget import TypesWidget
23
from Products.Archetypes.Registry import registerWidget
24
from Products.CMFPlone.i18nl10n import ulocalized_time
25
import json
26
27
28
class SplittedDateWidget(TypesWidget):
29
    _properties = TypesWidget._properties.copy()
30
    _properties.update({
31
        'ulocalized_time': ulocalized_time,
32
        'macro': "bika_health_widgets/splitteddatewidget",
33
        'helper_js': ("bika_health_widgets/splitteddatewidget.js",),
34
        'helper_css': ("bika_health_widgets/splitteddatewidget.css",),
35
        'changeYear': True,
36
        'changeMonth': True,
37
        'changeDay': True,
38
        'maxDate': '+0d',
39
        'yearRange': '-100:+0'
40
    })
41
    security = ClassSecurityInfo()
42
43
    def process_form(self, instance, field, form, empty_marker=None,
44
                     emptyReturnsMarker=False):
45
        outvalues = [{'year': form.get('PatientAgeAtCaseOnsetDate_year', empty_marker),
46
                     'month': form.get('PatientAgeAtCaseOnsetDate_month', empty_marker),
47
                     'day': form.get('PatientAgeAtCaseOnsetDate_day', empty_marker)}]
48
        return outvalues, {}
49
50
    def jsondumps(self, val):
51
        return json.dumps(val)
52
53
54
registerWidget(SplittedDateWidget,
55
               title='SplittedDateWidget',
56
               description=('Simple control with three input fields (year, month, day)'),
57
               )
58