EthnicitiesView.before_render()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 3
dl 6
loc 6
rs 10
c 0
b 0
f 0
cc 1
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 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.health import bikaMessageFactory as _
26
from bika.health.interfaces import IEthnicities
27
from plone.app.layout.globals.interfaces import IViewView
28
from plone.app.content.browser.interfaces import IFolderContentsView
29
from plone.app.folder.folder import ATFolder, ATFolderSchema
30
from zope.interface.declarations import implements
31
32
33 View Code Duplication
class EthnicitiesView(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(EthnicitiesView, self).__init__(context, request)
38
        self.catalog = 'bika_setup_catalog'
39
        self.contentFilter = {'portal_type': 'Ethnicity',
40
                              'sort_on': 'sortable_title'}
41
        self.context_actions = {_('Add'):
42
                                {'url': 'createObject?type_name=Ethnicity',
43
                                 'icon': '++resource++bika.lims.images/add.png'}}
44
        self.title = self.context.translate(_("Ethnicities"))
45
        self.icon = self.portal_url + "/++resource++bika.health.images/ethnicity_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': _('Ethnicity Name'),
54
                      'index': 'sortable_title'},
55
56
            'Description': {'title': _('Description'),
57
                            'index': 'description',
58
                            'toggle': False},
59
        }
60
61
        self.review_states = [
62
            {'id': 'default',
63
             'title': _('Active'),
64
             'contentFilter': {'is_active': True},
65
             'transitions': [{'id': 'deactivate'}, ],
66
             'columns': ['Title',
67
                         'Description']},
68
            {'id': 'inactive',
69
             'title': _('Dormant'),
70
             'contentFilter': {'is_active': False},
71
             'transitions': [{'id': 'activate'}, ],
72
             'columns': ['Title',
73
                         'Description']},
74
            {'id': 'all',
75
             'title': _('All'),
76
             'contentFilter': {},
77
             'columns': ['Title',
78
                         'Description']},
79
        ]
80
81
    def before_render(self):
82
        """Before template render hook
83
        """
84
        super(EthnicitiesView, self).before_render()
85
        # Don't allow any context actions on Ethnicities folder
86
        self.request.set("disable_border", 1)
87
88
    def folderitems(self):
89
        items = BikaListingView.folderitems(self)
90
        for x in range(len(items)):
91
            if not items[x].has_key('obj'): continue
92
            obj = items[x]['obj']
93
            items[x]['Description'] = obj.Description()
94
            items[x]['replace']['Title'] = "<a href='%s'>%s</a>" % \
95
                (items[x]['url'], items[x]['Title'])
96
97
        return items
98
99
schema = ATFolderSchema.copy()
100
101
102
class Ethnicities(ATFolder):
103
    implements(IEthnicities)
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(Ethnicities, PROJECTNAME)
109