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

PreservationsView.folderitem()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 5
dl 5
loc 5
rs 10
c 0
b 0
f 0
cc 1
nop 4
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 IPreservations
28
from bika.lims.permissions import AddPreservation
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 View Code Duplication
class PreservationsView(BikaListingView):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
35
36
    def __init__(self, context, request):
37
        super(PreservationsView, self).__init__(context, request)
38
        self.catalog = 'bika_setup_catalog'
39
        self.contentFilter = {'portal_type': 'Preservation',
40
                              'sort_on': 'sortable_title'}
41
        self.context_actions = {_('Add'):
42
                                {'url': 'createObject?type_name=Preservation',
43
                                 'permission': AddPreservation,
44
                                 'icon': '++resource++bika.lims.images/add.png'}}
45
        self.title = self.context.translate(_("Preservations"))
46
        self.icon = self.portal_url + "/++resource++bika.lims.images/preservation_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': _('Preservation'),
55
                      'index':'sortable_title'},
56
            'Description': {'title': _('Description'),
57
                            'index': 'description',
58
                            'toggle': True},
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': _('Inactive'),
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
        # Don't allow any context actions
85
        self.request.set("disable_border", 1)
86
87
    def folderitem(self, obj, item, index):
88
        obj = api.get_object(obj)
89
        item["Description"] = obj.Description()
90
        item["replace"]["Title"] = get_link(item["url"], item["Title"])
91
        return item
92
93
94
schema = ATFolderSchema.copy()
95
96
97
class Preservations(ATFolder):
98
    implements(IPreservations)
99
    displayContentsTab = False
100
    schema = schema
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable schema does not seem to be defined.
Loading history...
101
102
schemata.finalizeATCTSchema(schema, folderish = True, moveDiscussion = False)
103
atapi.registerType(Preservations, PROJECTNAME)
104