bika.health.controlpanel.bika_identifiertypes   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 106
Duplicated Lines 59.43 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A IdentifierTypesView.folderitems() 10 10 3
A IdentifierTypesView.before_render() 6 6 1
B IdentifierTypesView.__init__() 41 41 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.lims.browser.bika_listing import BikaListingView
24
from bika.health.config import PROJECTNAME
25
from bika.lims import bikaMessageFactory as _b
26
from bika.health import bikaMessageFactory as _
27
from bika.health.interfaces import IIdentifierTypes
28
from plone.app.layout.globals.interfaces import IViewView
29
from plone.app.content.browser.interfaces import IFolderContentsView
30
from plone.app.folder.folder import ATFolder, ATFolderSchema
31
from zope.interface.declarations import implements
32
33
34 View Code Duplication
class IdentifierTypesView(BikaListingView):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
35
    implements(IFolderContentsView, IViewView)
36
37
    def __init__(self, context, request):
38
        super(IdentifierTypesView, self).__init__(context, request)
39
        self.catalog = 'bika_setup_catalog'
40
        self.contentFilter = {'portal_type': 'IdentifierType',
41
                              'sort_on': 'sortable_title'}
42
        self.context_actions = {_('Add'):
43
                                {'url': 'createObject?type_name=IdentifierType',
44
                                 'icon': '++resource++bika.lims.images/add.png'}}
45
        self.title = self.context.translate(_("Identifier Types"))
46
        self.icon = self.portal_url + "/++resource++bika.health.images/identifiertype_big.png"
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(IdentifierTypesView, self).before_render()
84
        # Don't allow any context actions on Identifier types 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 IdentifierTypes(ATFolder):
100
    implements(IIdentifierTypes)
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(IdentifierTypes, PROJECTNAME)
106