DrugProhibitionsView.folderitems()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 10
Code Lines 9

Duplication

Lines 10
Ratio 100 %

Importance

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