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 |
|
|
|
|
146
|
|
|
|
147
|
|
|
|
148
|
|
|
schemata.finalizeATCTSchema(schema, folderish = True, moveDiscussion = False) |
149
|
|
|
atapi.registerType(VaccinationCenters, PROJECTNAME) |
150
|
|
|
|