bika.health.controlpanel.bika_casesyndromicclassifications   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 109
Duplicated Lines 58.72 %

Importance

Changes 0
Metric Value
wmc 5
eloc 75
dl 64
loc 109
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B CaseSyndromicClassificationsView.__init__() 42 42 1
A CaseSyndromicClassificationsView.before_render() 6 6 1
A CaseSyndromicClassificationsView.folderitems() 10 10 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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.SecurityInfo import ClassSecurityInfo
22
from Products.ATContentTypes.content import schemata
23
from Products.Archetypes import atapi
24
from Products.Archetypes.ArchetypeTool import registerType
25
from bika.lims.browser.bika_listing import BikaListingView
26
from bika.health.config import PROJECTNAME
27
from bika.lims import bikaMessageFactory as _b
28
from bika.health import bikaMessageFactory as _
29
from bika.lims.content.bikaschema import BikaFolderSchema
30
from bika.health.interfaces import ICaseSyndromicClassifications
31
from plone.app.layout.globals.interfaces import IViewView
32
from plone.app.content.browser.interfaces import IFolderContentsView
33
from plone.app.folder.folder import ATFolder, ATFolderSchema
34
from zope.interface.declarations import implements
35
36 View Code Duplication
class CaseSyndromicClassificationsView(BikaListingView):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
37
    implements(IFolderContentsView, IViewView)
38
39
    def __init__(self, context, request):
40
        super(CaseSyndromicClassificationsView, self).__init__(context, request)
41
        self.catalog = 'bika_setup_catalog'
42
        self.contentFilter = {'portal_type': 'CaseSyndromicClassification',
43
                              'sort_on': 'sortable_title'}
44
        self.context_actions = {_('Add'):
45
                                {'url': 'createObject?type_name=CaseSyndromicClassification',
46
                                 'icon': '++resource++bika.lims.images/add.png'}}
47
        self.title = self.context.translate(_("Case Syndromic Classifications"))
48
        self.icon = self.portal_url + "/++resource++bika.health.images/casesyndromicclassification_big.png"
49
        self.description = ""
50
        self.show_sort_column = False
51
        self.show_select_row = False
52
        self.show_select_column = True
53
        self.pagesize = 25
54
55
        self.columns = {
56
            'Title': {'title': _('Title'),
57
                      'index':'sortable_title'},
58
            'Description': {'title': _('Description'),
59
                            'index': 'description',
60
                            'toggle': True},
61
        }
62
63
        self.review_states = [
64
            {'id':'default',
65
             'title': _('Active'),
66
             'contentFilter': {'is_active': True},
67
             'transitions': [{'id':'deactivate'}, ],
68
             'columns': ['Title',
69
                         'Description']},
70
            {'id':'inactive',
71
             'title': _('Dormant'),
72
             'contentFilter': {'is_active': False},
73
             'transitions': [{'id':'activate'}, ],
74
             'columns': ['Title',
75
                         'Description']},
76
            {'id':'all',
77
             'title': _('All'),
78
             'contentFilter':{},
79
             'columns': ['Title',
80
                         'Description']},
81
        ]
82
83
    def before_render(self):
84
        """Before template render hook
85
        """
86
        super(CaseSyndromicClassificationsView, self).before_render()
87
        # Don't allow any context actions on Syndromic classifications folder
88
        self.request.set("disable_border", 1)
89
90
    def folderitems(self):
91
        items = BikaListingView.folderitems(self)
92
        for x in range(len(items)):
93
            if not items[x].has_key('obj'): continue
94
            obj = items[x]['obj']
95
            items[x]['Description'] = obj.Description()
96
            items[x]['replace']['Title'] = "<a href='%s'>%s</a>" % \
97
                 (items[x]['url'], items[x]['Title'])
98
99
        return items
100
101
schema = ATFolderSchema.copy()
102
class CaseSyndromicClassifications(ATFolder):
103
    implements(ICaseSyndromicClassifications)
104
    displayContentsTab = False
105
    schema = schema
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable schema does not seem to be defined.
Loading history...
106
107
schemata.finalizeATCTSchema(schema, folderish = True, moveDiscussion = False)
108
atapi.registerType(CaseSyndromicClassifications, PROJECTNAME)
109