Passed
Pull Request — 2.x (#1739)
by Jordi
05:29 queued 31s
created

senaite.core.browser.controlpanel.interpretationtemplates   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 48
dl 0
loc 103
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A InterpretationTemplatesView.__init__() 0 46 1
A InterpretationTemplatesView.folderitem() 0 10 1
A InterpretationTemplatesView.update() 0 4 1
A InterpretationTemplatesView.before_render() 0 4 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-2021 by it's authors.
19
# Some rights reserved, see README and LICENSE.
20
21
import collections
22
23
from bika.lims import _
24
from bika.lims.catalog import SETUP_CATALOG
25
from bika.lims.utils import get_link_for
26
27
from senaite.app.listing import ListingView
28
29
30
class InterpretationTemplatesView(ListingView):
31
    """Results Interpretation Templates listing view
32
    """
33
34
    def __init__(self, context, request):
35
        super(InterpretationTemplatesView, self).__init__(context, request)
36
37
        self.catalog = SETUP_CATALOG
38
39
        self.contentFilter = {
40
            "portal_type": "InterpretationTemplate",
41
            "sort_on": "created",
42
            "sort_order": "descending",
43
        }
44
45
        self.context_actions = {
46
            _("Add"): {
47
                "url": "++add++InterpretationTemplate",
48
                "icon": "add.png"}
49
            }
50
51
        self.show_select_column = True
52
53
        self.columns = collections.OrderedDict((
54
            ("Title", {
55
                "title": _("Title"),
56
                "index": "sortable_title"}),
57
            ("Description", {
58
                "title": _("Description"),
59
                "index": "Description"}),
60
        ))
61
62
        self.review_states = [
63
            {
64
                "id": "default",
65
                "title": _("Active"),
66
                "contentFilter": {"is_active": True},
67
                "transitions": [],
68
                "columns": self.columns.keys(),
69
            }, {
70
                "id": "inactive",
71
                "title": _("Inactive"),
72
                "contentFilter": {'is_active': False},
73
                "transitions": [],
74
                "columns": self.columns.keys(),
75
            }, {
76
                "id": "all",
77
                "title": _("All"),
78
                "contentFilter": {},
79
                "columns": self.columns.keys(),
80
            },
81
        ]
82
83
    def update(self):
84
        """Update hook
85
        """
86
        super(InterpretationTemplatesView, self).update()
87
88
    def before_render(self):
89
        """Before template render hook
90
        """
91
        super(InterpretationTemplatesView, self).before_render()
92
93
    def folderitem(self, obj, item, index):
94
        """Service triggered each time an item is iterated in folderitems.
95
        The use of this service prevents the extra-loops in child objects.
96
        :obj: the instance of the class to be foldered
97
        :item: dict containing the properties of the object to be used by
98
            the template
99
        :index: current index of the item
100
        """
101
        item["replace"]["Title"] = get_link_for(obj)
102
        return item
103