Passed
Push — master ( e3f582...5930d4 )
by Ramon
03:43
created

ReflexRuleFolderView.folderitems()   A

Complexity

Conditions 5

Size

Total Lines 13
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 13
rs 9.2833
c 0
b 0
f 0
cc 5
nop 1
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.CORE.
4
#
5
# SENAITE.CORE is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free Software
7
# 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-2020 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 Products.CMFCore import permissions
24
from Products.CMFCore.utils import getToolByName
25
from bika.lims import api
26
from bika.lims import bikaMessageFactory as _
27
from bika.lims.browser.bika_listing import BikaListingView
28
from bika.lims.config import PROJECTNAME
29
from bika.lims.interfaces import IReflexRuleFolder
30
from bika.lims.permissions import ManageBika, AddReflexRule
31
from bika.lims.utils import get_link
32
from bika.lims.utils import get_link_for
33
from plone.app.folder.folder import ATFolder
34
from plone.app.folder.folder import ATFolderSchema
35
from zope.interface.declarations import implements
36
37
38
class ReflexRuleFolderView(BikaListingView):
39
40
    def __init__(self, context, request):
41
        super(ReflexRuleFolderView, self).__init__(context, request)
42
        self.catalog = "portal_catalog"
43
        self.contentFilter = {
44
            'portal_type': 'ReflexRule',
45
            'path': {
46
                "query": "/".join(self.context.getPhysicalPath()),
47
                "level": 0
48
            },
49
        }
50
51
        self.show_select_row = False
52
        self.show_select_column = True
53
        self.icon = self.portal_url +\
54
            "/++resource++bika.lims.images/reflexrule_big.png"
55
        self.title = self.context.translate(_("Reflex rules folder"))
56
        self.description = ""
57
        self.columns = {
58
            'Title': {
59
                'title': _('Reflex Rule'),
60
                'index': 'sortable_title'
61
            },
62
            'Method': {
63
                'title': _('Method'),
64
                'index': 'sortable_title'
65
            }
66
        }
67
        self.review_states = [
68
            {'id': 'default',
69
             'title': _('Active'),
70
             'contentFilter': {'is_active': True},
71
             'columns': ['Title', 'Method', ]},
72
            {'id': 'inactive',
73
             'title': _('Inactive'),
74
             'contentFilter': {'is_active': False},
75
             'columns': ['Title', 'Method', ]},
76
            {'id': 'all',
77
             'title': _('All'),
78
             'contentFilter': {},
79
             'columns': ['Title', 'Method', ]},
80
        ]
81
82
    def __call__(self):
83
        mtool = getToolByName(self.context, 'portal_membership')
84
        if mtool.checkPermission(
85
                permissions.ModifyPortalContent,
86
                self.context):
87
            self.context_actions[_('Add Reflex rule')] = {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable _ does not seem to be defined.
Loading history...
88
                'url': 'createObject?type_name=ReflexRule',
89
                'permission': AddReflexRule,
90
                'icon': '++resource++bika.lims.images/add.png'
91
            }
92
        if not mtool.checkPermission(ManageBika, self.context):
93
            self.show_select_column = False
94
            self.review_states = [
95
                {'id': 'default',
96
                 'title': _('All'),
97
                 'contentFilter': {},
98
                 'columns': ['Title']}
99
            ]
100
        return super(ReflexRuleFolderView, self).__call__()
101
102
    def before_render(self):
103
        """Before template render hook
104
        """
105
        # Don't allow any context actions
106
        self.request.set("disable_border", 1)
107
108
    def folderitem(self, obj, item, index):
109
        obj = api.get_object(obj)
110
        method = obj.getMethod()
111
        if method:
112
            item["Method"] = api.get_title(method)
113
            item["replace"]["Method"] = get_link_for(method)
114
115
        item["replace"]["Title"] = get_link(item["url"], item["Title"])
116
        return item
117
118
119
schema = ATFolderSchema.copy()
120
121
122
class ReflexRuleFolder(ATFolder):
123
    implements(IReflexRuleFolder)
124
    displayContentsTab = False
125
    schema = schema
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable schema does not seem to be defined.
Loading history...
126
127
128
schemata.finalizeATCTSchema(
129
    schema,
130
    folderish=True,
131
    moveDiscussion=False)
132
133
atapi.registerType(ReflexRuleFolder, PROJECTNAME)
134