bika.health.controlpanel.bika_aetiologicagents   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 106
Duplicated Lines 60.38 %

Importance

Changes 0
Metric Value
wmc 5
eloc 71
dl 64
loc 106
rs 10
c 0
b 0
f 0

3 Methods

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

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