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

bika.lims.controlpanel.bika_batchlabels   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 58
dl 0
loc 93
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A BatchLabelsView.before_render() 0 5 1
A BatchLabelsView.__init__() 0 37 1
A BatchLabelsView.folderitem() 0 3 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 bika.lims import api
24
from bika.lims import bikaMessageFactory as _
25
from bika.lims.browser.bika_listing import BikaListingView
26
from bika.lims.config import PROJECTNAME
27
from bika.lims.interfaces import IBatchLabels
28
from bika.lims.permissions import AddBatchLabel
29
from bika.lims.utils import get_link
30
from plone.app.folder.folder import ATFolder, ATFolderSchema
31
from zope.interface.declarations import implements
32
33
34
class BatchLabelsView(BikaListingView):
35
36
    def __init__(self, context, request):
37
        super(BatchLabelsView, self).__init__(context, request)
38
        self.catalog = 'bika_setup_catalog'
39
        self.contentFilter = {'portal_type': 'BatchLabel',
40
                              'sort_on': 'sortable_title'}
41
        self.context_actions = {_('Add'):
42
                                {'url': 'createObject?type_name=BatchLabel',
43
                                 'permission': AddBatchLabel,
44
                                 'icon': '++resource++bika.lims.images/add.png'}}
45
        self.title = self.context.translate(_("Batch Labels"))
46
        self.icon = self.portal_url + "/++resource++bika.lims.images/batchlabel_big.png"
47
        self.description = ""
48
49
        self.show_select_row = False
50
        self.show_select_column = True
51
        self.pagesize = 25
52
53
        self.columns = {
54
            'Title': {'title': _('Label'),
55
                      'index':'sortable_title'},
56
        }
57
58
        self.review_states = [
59
            {'id':'default',
60
             'title': _('Active'),
61
             'contentFilter': {'is_active': True},
62
             'transitions': [{'id':'deactivate'}, ],
63
             'columns': ['Title']},
64
            {'id':'inactive',
65
             'title': _('Inactive'),
66
             'contentFilter': {'is_active': False},
67
             'transitions': [{'id':'activate'}, ],
68
             'columns': ['Title']},
69
            {'id':'all',
70
             'title': _('All'),
71
             'contentFilter':{},
72
             'columns': ['Title']},
73
        ]
74
75
    def before_render(self):
76
        """Before template render hook
77
        """
78
        # Don't allow any context actions
79
        self.request.set("disable_border", 1)
80
81
    def folderitem(self, obj, item, index):
82
        item["replace"]["Title"] = get_link(item["url"], item["Title"])
83
        return item
84
85
schema = ATFolderSchema.copy()
86
class BatchLabels(ATFolder):
87
    implements(IBatchLabels)
88
    displayContentsTab = False
89
    schema = schema
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable schema does not seem to be defined.
Loading history...
90
91
schemata.finalizeATCTSchema(schema, folderish = True, moveDiscussion = False)
92
atapi.registerType(BatchLabels, PROJECTNAME)
93