Completed
Push — master ( 65c723...b6585a )
by Jordi
76:39 queued 72:29
created

DynamicAnalysisSpecsView.before_render()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
# -*- coding: utf-8 -*-
2
3
import collections
4
5
from bika.lims import _
6
from bika.lims.catalog import SETUP_CATALOG
7
from plone.dexterity.content import Container
8
from plone.supermodel import model
9
from senaite.core.listing import ListingView
10
from zope import schema
11
from zope.interface import implements
12
13
14
class IDynamicAnalysisSpecs(model.Schema):
15
    """Dynamic Analysis Specifications
16
    """
17
    title = schema.TextLine(
18
        title=_(u"Title"),
19
        description=_(u"Title of the Folder"),
20
        required=True)
21
22
23
class DynamicAnalysisSpecsView(ListingView):
24
    """Displays all system's dynamic analysis specifications
25
    """
26
27 View Code Duplication
    def __init__(self, context, request):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
28
        super(DynamicAnalysisSpecsView, self).__init__(context, request)
29
30
        self.catalog = SETUP_CATALOG
31
32
        self.contentFilter = {
33
            "portal_type": "DynamicAnalysisSpec",
34
            "sort_on": "created",
35
            "sort_order": "descending",
36
        }
37
38
        self.context_actions = {
39
            _("Add"): {
40
                "url": "++add++DynamicAnalysisSpec",
41
                "permission": "cmf.AddPortalContent",
42
                "icon": "++resource++bika.lims.images/add.png"}
43
            }
44
45
        self.icon = "{}/{}/{}".format(
46
            self.portal_url,
47
            "/++resource++bika.lims.images",
48
            "analysisspec_big.png"
49
        )
50
51
        self.title = self.context.Title()
52
        self.description = self.context.Description()
53
        self.show_select_column = True
54
        self.pagesize = 25
55
56
        self.columns = collections.OrderedDict((
57
            ("Title", {
58
                "title": _("Title"),
59
                "replace_url": "absolute_url",
60
                "index": "sortable_title"}),
61
            ("Description", {
62
                "title": _("Description"),
63
                "index": "Description"}),
64
        ))
65
66
        self.review_states = [
67
            {
68
                "id": "default",
69
                "title": _("Active"),
70
                "contentFilter": {"is_active": True},
71
                "transitions": [],
72
                "columns": self.columns.keys(),
73
            }, {
74
                "id": "inactive",
75
                "title": _("Inactive"),
76
                "contentFilter": {'is_active': False},
77
                "transitions": [],
78
                "columns": self.columns.keys(),
79
            }, {
80
                "id": "all",
81
                "title": _("All"),
82
                "contentFilter": {},
83
                "columns": self.columns.keys(),
84
            },
85
        ]
86
87
    def update(self):
88
        """Update hook
89
        """
90
        super(DynamicAnalysisSpecsView, self).update()
91
92
    def before_render(self):
93
        """Before template render hook
94
        """
95
        super(DynamicAnalysisSpecsView, self).before_render()
96
        # Don't allow any context actions
97
        self.request.set("disable_border", 1)
98
99
    def folderitem(self, obj, item, index):
100
        """Service triggered each time an item is iterated in folderitems.
101
        The use of this service prevents the extra-loops in child objects.
102
        :obj: the instance of the class to be foldered
103
        :item: dict containing the properties of the object to be used by
104
            the template
105
        :index: current index of the item
106
        """
107
        return item
108
109
110
class DynamicAnalysisSpecs(Container):
111
    """Dynamic Analysis Specifications Folder
112
    """
113
    implements(IDynamicAnalysisSpecs)
114