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-2024 by it's authors. |
19
|
|
|
# Some rights reserved, see README and LICENSE. |
20
|
|
|
|
21
|
|
|
from AccessControl import ClassSecurityInfo |
22
|
|
|
from bika.lims import api |
23
|
|
|
from bika.lims.interfaces import IClient |
24
|
|
|
from bika.lims.utils import chain |
25
|
|
|
from senaite.core.content.base import Container |
26
|
|
|
from senaite.core.interfaces import IClientAwareMixin |
27
|
|
|
from zope.interface import implementer |
28
|
|
|
|
29
|
|
|
|
30
|
|
View Code Duplication |
@implementer(IClientAwareMixin) |
|
|
|
|
31
|
|
|
class ClientAwareMixin(Container): |
32
|
|
|
security = ClassSecurityInfo() |
33
|
|
|
|
34
|
|
|
@security.public |
35
|
|
|
def getClient(self): |
36
|
|
|
"""Returns the Client the object is bound to, if any |
37
|
|
|
""" |
38
|
|
|
# Look in the acquisition chain |
39
|
|
|
for obj in chain(self): |
40
|
|
|
if IClient.providedBy(obj): |
41
|
|
|
return obj |
42
|
|
|
|
43
|
|
|
# Look in Schema |
44
|
|
|
fields = api.get_fields(self) |
45
|
|
|
client_field = fields.get("Client") |
46
|
|
|
if client_field: |
47
|
|
|
client = client_field.get(self) |
48
|
|
|
client = api.get_object(client, None) |
49
|
|
|
if client and IClient.providedBy(client): |
50
|
|
|
return client |
51
|
|
|
|
52
|
|
|
# No client bound |
53
|
|
|
return None |
54
|
|
|
|
55
|
|
|
@security.public |
56
|
|
|
def getClientUID(self): |
57
|
|
|
"""Returns the Client UID the object is bound to, if any |
58
|
|
|
""" |
59
|
|
|
client = self.getClient() |
60
|
|
|
return client and api.get_uid(client) or "" |
61
|
|
|
|
62
|
|
|
@security.public |
63
|
|
|
def getClientID(self): |
64
|
|
|
"""Returns the Client ID the object is bound to, if any |
65
|
|
|
""" |
66
|
|
|
client = self.getClient() |
67
|
|
|
return client and client.getClientID() or "" |
68
|
|
|
|
69
|
|
|
@security.public |
70
|
|
|
def getClientTitle(self): |
71
|
|
|
"""Returns the Client Title the object is bound to, if any |
72
|
|
|
""" |
73
|
|
|
client = self.getClient() |
74
|
|
|
return client and client.Title() or "" |
75
|
|
|
|
76
|
|
|
@security.public |
77
|
|
|
def getClientURL(self): |
78
|
|
|
client = self.getClient() |
79
|
|
|
return client and client.absolute_url_path() or "" |
80
|
|
|
|