| @@ 31-80 (lines=50) @@ | ||
| 28 | from bika.lims.utils import chain |
|
| 29 | ||
| 30 | ||
| 31 | class ClientAwareMixin(BaseObject): |
|
| 32 | implements(IClientAwareMixin) |
|
| 33 | ||
| 34 | security = ClassSecurityInfo() |
|
| 35 | ||
| 36 | @security.public |
|
| 37 | def getClient(self): |
|
| 38 | """Returns the Client the object is bound to, if any |
|
| 39 | """ |
|
| 40 | # Look in the acquisition chain |
|
| 41 | for obj in chain(self): |
|
| 42 | if IClient.providedBy(obj): |
|
| 43 | return obj |
|
| 44 | ||
| 45 | # Look in Schema |
|
| 46 | client_field = self.Schema().get("Client", default=None) |
|
| 47 | if client_field: |
|
| 48 | client = client_field.get(self) |
|
| 49 | client = api.get_object(client, None) |
|
| 50 | if client and IClient.providedBy(client): |
|
| 51 | return client |
|
| 52 | ||
| 53 | # No client bound |
|
| 54 | return None |
|
| 55 | ||
| 56 | @security.public |
|
| 57 | def getClientUID(self): |
|
| 58 | """Returns the Client UID the object is bound to, if any |
|
| 59 | """ |
|
| 60 | client = self.getClient() |
|
| 61 | return client and api.get_uid(client) or "" |
|
| 62 | ||
| 63 | @security.public |
|
| 64 | def getClientID(self): |
|
| 65 | """Returns the Client ID the object is bound to, if any |
|
| 66 | """ |
|
| 67 | client = self.getClient() |
|
| 68 | return client and client.getClientID() or "" |
|
| 69 | ||
| 70 | @security.public |
|
| 71 | def getClientTitle(self): |
|
| 72 | """Returns the Client Title the object is bound to, if any |
|
| 73 | """ |
|
| 74 | client = self.getClient() |
|
| 75 | return client and client.Title() or "" |
|
| 76 | ||
| 77 | @security.public |
|
| 78 | def getClientURL(self): |
|
| 79 | client = self.getClient() |
|
| 80 | return client and client.absolute_url_path() or "" |
|
| 81 | ||
| @@ 30-79 (lines=50) @@ | ||
| 27 | from zope.interface import implementer |
|
| 28 | ||
| 29 | ||
| 30 | @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 | ||