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

SubGroupsView.folderitems()   A

Complexity

Conditions 3

Size

Total Lines 11
Code Lines 10

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 10
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
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 AccessControl.SecurityInfo import ClassSecurityInfo
22
from Products.ATContentTypes.content import schemata
23
from Products.Archetypes import atapi
24
from bika.lims import api
25
from bika.lims import bikaMessageFactory as _
26
from bika.lims.browser.bika_listing import BikaListingView
27
from bika.lims.config import PROJECTNAME
28
from bika.lims.interfaces import ISubGroups
29
from bika.lims.permissions import AddSubGroup
30
from bika.lims.utils import get_link
31
from plone.app.folder.folder import ATFolder
32
from plone.app.folder.folder import ATFolderSchema
33
from zope.interface.declarations import implements
34
35
36 View Code Duplication
class SubGroupsView(BikaListingView):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
37
38
    def __init__(self, context, request):
39
        super(SubGroupsView, self).__init__(context, request)
40
        self.catalog = 'bika_setup_catalog'
41
        self.contentFilter = {'portal_type': 'SubGroup',
42
                              'sort_on': 'sortable_title'}
43
        self.context_actions = {
44
            _('Add'): {
45
                'url': 'createObject?type_name=SubGroup',
46
                'permission': AddSubGroup,
47
                'icon': '++resource++bika.lims.images/add.png'
48
            }
49
        }
50
        self.icon = self.portal_url + \
51
            "/++resource++bika.lims.images/batch_big.png"
52
        self.title = self.context.translate(_("Sub-groups"))
53
        self.description = ""
54
55
        self.show_select_row = False
56
        self.show_select_column = True
57
        self.pagesize = 25
58
59
        self.columns = {
60
            'Title': {'title': _('Sub-group'),
61
                      'index': 'sortable_title'},
62
            'Description': {'title': _('Description'),
63
                            'index': 'description',
64
                            'toggle': True},
65
            'SortKey': {'title': _('Sort Key')},
66
        }
67
68
        self.review_states = [
69
            {'id': 'default',
70
             'title': _('Active'),
71
             'contentFilter': {'is_active': True},
72
             'transitions': [{'id': 'deactivate'}, ],
73
             'columns': ['Title', 'Description', 'SortKey']},
74
            {'id': 'inactive',
75
             'title': _('Inactive'),
76
             'contentFilter': {'is_active': False},
77
             'transitions': [{'id': 'activate'}, ],
78
             'columns': ['Title', 'Description', 'SortKey']},
79
            {'id': 'all',
80
             'title': _('All'),
81
             'contentFilter': {},
82
             'columns': ['Title', 'Description', 'SortKey']},
83
        ]
84
85
    def before_render(self):
86
        """Before template render hook
87
        """
88
        # Don't allow any context actions
89
        self.request.set("disable_border", 1)
90
91
    def folderitem(self, obj, item, index):
92
        obj = api.get_object(obj)
93
        item["Description"] = obj.Description()
94
        item["replace"]["Title"] = get_link(item["url"], item["Title"])
95
        return item
96
97
98
schema = ATFolderSchema.copy()
99
100
101
class SubGroups(ATFolder):
102
    implements(ISubGroups)
103
    security = ClassSecurityInfo()
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(SubGroups, PROJECTNAME)
109