bika.health.widgets.casebasalbodytempwidget   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 34
dl 0
loc 60
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A CaseBasalBodyTempWidget.getBasalBodyTemperature() 0 7 1
A CaseBasalBodyTempWidget.jsondumps() 0 2 1
A CaseBasalBodyTempWidget.process_form() 0 9 2
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.ATExtensions.widget import RecordsWidget as ATRecordsWidget
23
from Products.Archetypes.Registry import registerWidget
24
import json
25
26
27
class CaseBasalBodyTempWidget(ATRecordsWidget):
28
    security = ClassSecurityInfo()
29
    _properties = ATRecordsWidget._properties.copy()
30
    _properties.update({
31
        'macro': "bika_health_widgets/casebasalbodytempwidget",
32
        'helper_js': ("bika_health_widgets/casebasalbodytempwidget.js",),
33
        'helper_css': ("bika_health_widgets/casebasalbodytempwidget.css",),
34
    })
35
36
    def process_form(self, instance, field, form, empty_marker=None,
37
                     emptyReturnsMarker=False):
38
        outvalues = []
39
        values = form.get(field.getName(), empty_marker)
40
        for value in values:
41
            outvalues.append({'Day1': value.get('Day1', ''),
42
                              'Day2': value.get('Day2', ''),
43
                              'Day3': value.get('Day3', '')})
44
        return outvalues, {}
45
46
    def jsondumps(self, val):
47
        return json.dumps(val)
48
49
    def getBasalBodyTemperature(self):
50
        conditions = [{'Day1': '',
51
                       'Day2': '',
52
                       'Day3': ''}]
53
        field = self.aq_parent.Schema()['BasalBodyTemperature']
54
        value = field.get(self.aq_parent)
55
        return value and value or conditions
56
57
registerWidget(CaseBasalBodyTempWidget,
58
               title='CaseBasalBodyTempWidget',
59
               description='Basal body temperature',)
60