bika.health.controlpanel.bika_vaccinationcenters   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 83
dl 0
loc 150
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A VaccinationCentersView.before_render() 0 6 1
A VaccinationCentersView.folderitem() 0 17 1
B VaccinationCentersView.__init__() 0 63 1
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.HEALTH.
4
#
5
# SENAITE.HEALTH is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by the Free
7
# Software 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-2019 by it"s authors.
19
# Some rights reserved, see README and LICENSE.
20
21
import collections
22
23
from Products.ATContentTypes.content import schemata
24
from Products.Archetypes import atapi
25
from plone.app.content.browser.interfaces import IFolderContentsView
26
from plone.app.folder.folder import ATFolder
27
from plone.app.folder.folder import ATFolderSchema
28
from plone.app.layout.globals.interfaces import IViewView
29
from zope.interface import implements
30
31
from bika.health import bikaMessageFactory as _
32
from bika.health.config import PROJECTNAME
33
from bika.health.interfaces import IVaccinationCenters
34
from bika.health.permissions import AddVaccinationCenter
35
from bika.lims import api
36
from bika.lims.browser.bika_listing import BikaListingView
37
from bika.lims.catalog.bikasetup_catalog import SETUP_CATALOG
38
from bika.lims.utils import get_link
39
40
41
# TODO: Separate content and view into own modules!
42
43
44
class VaccinationCentersView(BikaListingView):
45
    implements(IFolderContentsView, IViewView)
46
47
    def __init__(self, context, request):
48
        super(VaccinationCentersView, self).__init__(context, request)
49
50
        self.catalog = SETUP_CATALOG
51
        self.contentFilter = dict(
52
            portal_type="VaccinationCenter",
53
            sort_on="sortable_title"
54
        )
55
56
        self.context_actions = {
57
            _("Add"): {
58
                "url": "createObject?type_name=VaccinationCenter",
59
                "permission": AddVaccinationCenter,
60
                "icon": "++resource++bika.lims.images/add.png"}
61
        }
62
63
        self.title = self.context.translate(_("Vaccination Centers"))
64
        self.icon = "{}/{}".format(
65
            self.portal_url,
66
            "/++resource++bika.health.images/vaccinationcenter_big.png"
67
        )
68
69
        self.show_select_row = False
70
        self.show_select_column = True
71
        self.pagesize = 50
72
73
        self.columns = collections.OrderedDict((
74
            ("Name", {
75
                "title": _("Name"),
76
                "index": "sortable_title"
77
            }),
78
            ("Email", {
79
                "title": _("Email"),
80
                "toggle": True
81
            }),
82
            ("Phone", {
83
                "title": _("Phone"),
84
                "toggle": True
85
            }),
86
            ("Fax", {
87
                "title": _("Fax"),
88
                "toggle": True
89
            }),
90
        ))
91
92
        self.review_states = [
93
            {
94
                "id":"default",
95
                "title": _("Active"),
96
                "contentFilter": {"is_active": True},
97
                "transitions": [{"id": "deactivate"}, ],
98
                "columns": self.columns.keys(),
99
            }, {
100
                "id":"inactive",
101
                "title": _("Dormant"),
102
                "contentFilter": {"is_active": False},
103
                "transitions": [{"id": "activate"}, ],
104
                "columns": self.columns.keys(),
105
            }, {
106
                "id":"all",
107
                "title": _("All"),
108
                "contentFilter":{},
109
                "columns": self.columns.keys(),
110
            },
111
        ]
112
113
    def before_render(self):
114
        """Before template render hook
115
        """
116
        super(VaccinationCentersView, self).before_render()
117
        # Don"t allow any context actions
118
        self.request.set("disable_border", 1)
119
120
    def folderitem(self, obj, item, index):
121
        """Service triggered each time an item is iterated in folderitems.
122
        The use of this service prevents the extra-loops in child objects.
123
        :obj: the instance of the class to be foldered
124
        :item: dict containing the properties of the object to be used by
125
            the template
126
        :index: current index of the item
127
        """
128
        name = obj.getName()
129
        url = api.get_url(obj)
130
131
        item["Email"] = obj.getEmailAddress()
132
        item["Phone"] = obj.getPhone()
133
        item["Fax"] = obj.getFax()
134
        item["replace"]["Name"] = get_link(url, value=name)
135
136
        return item
137
138
139
schema = ATFolderSchema.copy()
140
141
142
class VaccinationCenters(ATFolder):
143
    implements(IVaccinationCenters)
144
    displayContentsTab = False
145
    schema = schema
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable schema does not seem to be defined.
Loading history...
146
147
148
schemata.finalizeATCTSchema(schema, folderish = True, moveDiscussion = False)
149
atapi.registerType(VaccinationCenters, PROJECTNAME)
150