|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
from senaite.core.schema.interfaces import IBaseField |
|
4
|
|
|
from z3c.form.datamanager import AttributeField |
|
5
|
|
|
from z3c.form.datamanager import DictionaryField |
|
6
|
|
|
from zope.component import adapts |
|
7
|
|
|
from zope.interface import Interface |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class AttributeDataManager(AttributeField): |
|
11
|
|
|
"""Senaite Data Manager for Attribute Fields |
|
12
|
|
|
|
|
13
|
|
|
Original implementation: `z3c.form.datamanager` |
|
14
|
|
|
|
|
15
|
|
|
NOTE: The original implementation does not use the setter/getter of the |
|
16
|
|
|
field, see z3c/form/datamanager.txt for explanation. |
|
17
|
|
|
|
|
18
|
|
|
However, we want to have that control at field level and also be able to |
|
19
|
|
|
execute some custom logic when getting/setting the values, e.g. fire |
|
20
|
|
|
modification events, check permissions, audit-logging etc. |
|
21
|
|
|
""" |
|
22
|
|
|
adapts(Interface, IBaseField) |
|
23
|
|
|
|
|
24
|
|
|
def __init__(self, context, field): |
|
25
|
|
|
super(AttributeDataManager, self).__init__(context, field) |
|
26
|
|
|
|
|
27
|
|
|
def get(self): |
|
28
|
|
|
"""Delegate to the field getter |
|
29
|
|
|
""" |
|
30
|
|
|
return self.field.get(self.adapted_context) |
|
31
|
|
|
|
|
32
|
|
|
def set(self, value): |
|
33
|
|
|
"""Delegate to the field setter |
|
34
|
|
|
""" |
|
35
|
|
|
self.field.set(self.adapted_context, value) |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
class DictionaryDataManager(DictionaryField): |
|
39
|
|
|
"""Senaite Data Manager for Dictionary Fields |
|
40
|
|
|
|
|
41
|
|
|
Original implementation: `z3c.form.datamanager` |
|
42
|
|
|
|
|
43
|
|
|
Currently only implemented as a boiler plate for eventual later use. |
|
44
|
|
|
""" |
|
45
|
|
|
adapts(dict, IBaseField) |
|
46
|
|
|
|
|
47
|
|
|
def __init__(self, data, field): |
|
48
|
|
|
super(DictionaryDataManager, self).__init__(data, field) |
|
49
|
|
|
|