bika.health.widgets.readonlystringwidget   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 21
dl 0
loc 46
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ReadonlyStringWidget.readonly() 0 6 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.Archetypes.Registry import registerWidget
23
from Products.Archetypes.Widget import StringWidget
24
from Products.CMFCore.permissions import View
25
from zope.component import getMultiAdapter
26
27
class ReadonlyStringWidget(StringWidget):
28
    _properties = StringWidget._properties.copy()
29
    _properties.update({
30
        'macro' : "bika_health_widgets/readonlystringwidget",
31
        'css' : "readonly",
32
        })
33
    security = ClassSecurityInfo()
34
35
    security.declareProtected(View, 'readonly')
36
    def readonly(self, context, request):
37
        portal_state = getMultiAdapter((context, request), name="plone_portal_state")
38
        if portal_state.anonymous():
39
            return None
40
        else:
41
            return '1'
42
43
registerWidget(ReadonlyStringWidget,
44
               title='ReadonlyString',
45
               description=('HTML input text in readonly mode'),
46
               )
47