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
|
|
|
from bika.lims import AddBatch |
22
|
|
|
from bika.lims import api |
23
|
|
|
from bika.lims import bikaMessageFactory as _ |
24
|
|
|
from bika.lims.api.security import check_permission |
25
|
|
|
from bika.lims.browser.batchfolder import BatchFolderContentsView |
26
|
|
|
from bika.lims.interfaces import IClient |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
# TODO Remove for compatibility with senaite.core v1.3.3 |
30
|
|
|
# Superseded by https://github.com/senaite/senaite.core/pull/1467 |
31
|
|
|
def update(self): |
32
|
|
|
"""Before template render hook |
33
|
|
|
""" |
34
|
|
|
super(BatchFolderContentsView, self).update() |
35
|
|
|
|
36
|
|
|
if self.context.portal_type == "BatchFolder": |
37
|
|
|
self.request.set("disable_border", 1) |
38
|
|
|
|
39
|
|
|
# By default, only users with AddBatch permissions for the current |
40
|
|
|
# context can add batches. |
41
|
|
|
self.context_actions = { |
42
|
|
|
_("Add"): { |
|
|
|
|
43
|
|
|
"url": "createObject?type_name=Batch", |
44
|
|
|
"permission": AddBatch, |
45
|
|
|
"icon": "++resource++bika.lims.images/add.png" |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
# If current user is a client contact and current context is not a |
50
|
|
|
# Client, then modify the url for Add action so the Batch gets created |
51
|
|
|
# inside the Client object to which the current user belongs. The |
52
|
|
|
# reason is that Client contacts do not have privileges to create |
53
|
|
|
# Batches inside portal/batches |
54
|
|
|
if not IClient.providedBy(self.context): |
55
|
|
|
# Get the client the current user belongs to |
56
|
|
|
client = api.get_current_client() |
57
|
|
|
if client and check_permission(AddBatch, client): |
58
|
|
|
add_url = self.context_actions[_("Add")]["url"] |
59
|
|
|
add_url = "{}/{}".format(api.get_url(client), add_url) |
60
|
|
|
self.context_actions[_("Add")]["url"] = add_url |
61
|
|
|
del (self.context_actions[_("Add")]["permission"]) |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
# TODO Remove for compatibility with senaite.core v1.3.3 |
65
|
|
|
# Superseded by https://github.com/senaite/senaite.core/pull/1467 |
66
|
|
|
def before_render(self): |
67
|
|
|
"""Before template render hook |
68
|
|
|
""" |
69
|
|
|
super(BatchFolderContentsView, self).before_render() |
70
|
|
|
|