Passed
Push — master ( f42093...226b52 )
by Ramon
04:24
created

ClientAwareMixin.getClientUID()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
from AccessControl import ClassSecurityInfo
2
from Products.Archetypes.BaseObject import BaseObject
3
from zope.interface import implements
4
5
from bika.lims import api
6
from bika.lims.interfaces import IClient
7
from bika.lims.interfaces import IClientAwareMixin
8
from bika.lims.utils import chain
9
10
11
class ClientAwareMixin(BaseObject):
12
    implements(IClientAwareMixin)
13
14
    security = ClassSecurityInfo()
15
16
    @security.public
17
    def getClient(self):
18
        """Returns the Client the object is bound to, if any
19
        """
20
        # Look in the acquisition chain
21
        for obj in chain(self):
22
            if IClient.providedBy(obj):
23
                return obj
24
25
        # Look in Schema
26
        client_field = self.Schema().get("Client", default=None)
27
        if client_field:
28
            client = client_field.get(self)
29
            client = api.get_object(client, None)
30
            if client and IClient.providedBy(client):
31
                return client
32
33
        # No client bound
34
        return None
35
36
    @security.public
37
    def getClientUID(self):
38
        """Returns the Client UID the object is bound to, if any
39
        """
40
        client = self.getClient()
41
        return client and api.get_uid(client) or ""
42
43
    @security.public
44
    def getClientID(self):
45
        """Returns the Client ID the object is bound to, if any
46
        """
47
        client = self.getClient()
48
        return client and client.getClientID() or ""
49
50
    @security.public
51
    def getClientTitle(self):
52
        """Returns the Client Title the object is bound to, if any
53
        """
54
        client = self.getClient()
55
        return client and client.Title() or ""
56
57
    @security.public
58
    def getClientURL(self):
59
        client = self.getClient()
60
        return client and client.absolute_url_path() or ""
61