|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
from AccessControl import ClassSecurityInfo |
|
4
|
|
|
from bika.lims import api |
|
5
|
|
|
from plone.dexterity.content import Container as BaseContainer |
|
6
|
|
|
from plone.dexterity.content import Item as BaseItem |
|
7
|
|
|
from senaite.core.interfaces import IContainer |
|
8
|
|
|
from senaite.core.interfaces import IItem |
|
9
|
|
|
from zope.interface import implementer |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
@implementer(IContainer) |
|
13
|
|
|
class Container(BaseContainer): |
|
14
|
|
|
"""Base class for SENAITE folderish contents |
|
15
|
|
|
""" |
|
16
|
|
|
security = ClassSecurityInfo() |
|
17
|
|
|
|
|
18
|
|
|
@security.private |
|
19
|
|
|
def accessor(self, fieldname): |
|
20
|
|
|
"""Return the field accessor for the fieldname |
|
21
|
|
|
""" |
|
22
|
|
|
schema = api.get_schema(self) |
|
23
|
|
|
if fieldname not in schema: |
|
24
|
|
|
return None |
|
25
|
|
|
return schema[fieldname].get |
|
26
|
|
|
|
|
27
|
|
|
@security.private |
|
28
|
|
|
def mutator(self, fieldname): |
|
29
|
|
|
"""Return the field mutator for the fieldname |
|
30
|
|
|
""" |
|
31
|
|
|
schema = api.get_schema(self) |
|
32
|
|
|
if fieldname not in schema: |
|
33
|
|
|
return None |
|
34
|
|
|
return schema[fieldname].set |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
@implementer(IItem) |
|
38
|
|
|
class Item(BaseItem): |
|
39
|
|
|
"""Base class for SENAITE contentish contents |
|
40
|
|
|
""" |
|
41
|
|
|
security = ClassSecurityInfo() |
|
42
|
|
|
|
|
43
|
|
|
@security.private |
|
44
|
|
|
def accessor(self, fieldname): |
|
45
|
|
|
"""Return the field accessor for the fieldname |
|
46
|
|
|
""" |
|
47
|
|
|
schema = api.get_schema(self) |
|
48
|
|
|
if fieldname not in schema: |
|
49
|
|
|
return None |
|
50
|
|
|
return schema[fieldname].get |
|
51
|
|
|
|
|
52
|
|
|
@security.private |
|
53
|
|
|
def mutator(self, fieldname): |
|
54
|
|
|
"""Return the field mutator for the fieldname |
|
55
|
|
|
""" |
|
56
|
|
|
schema = api.get_schema(self) |
|
57
|
|
|
if fieldname not in schema: |
|
58
|
|
|
return None |
|
59
|
|
|
return schema[fieldname].set |
|
60
|
|
|
|