|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
from bika.lims import senaiteMessageFactory as _ |
|
4
|
|
|
from plone.app.registry.browser.controlpanel import ControlPanelFormWrapper |
|
5
|
|
|
from plone.app.registry.browser.controlpanel import RegistryEditForm |
|
6
|
|
|
from plone.registry.interfaces import IRegistry |
|
7
|
|
|
from plone.z3cform import layout |
|
8
|
|
|
from senaite.core.registry import get_registry_interfaces |
|
9
|
|
|
from senaite.core.registry.schema import ISenaiteRegistry |
|
10
|
|
|
from zope.component import getUtility |
|
11
|
|
|
from zope.interface import alsoProvides |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class ContextProxy(object): |
|
15
|
|
|
"""Lookup fields from extended interfaces |
|
16
|
|
|
|
|
17
|
|
|
Code taken from here: |
|
18
|
|
|
https://github.com/bluedynamics/bda.plone.shop/blob/master/src/bda/plone/shop/browser/controlpanel.py |
|
19
|
|
|
""" |
|
20
|
|
|
def __init__(self, interfaces): |
|
21
|
|
|
self.__interfaces = interfaces |
|
22
|
|
|
alsoProvides(self, *interfaces) |
|
23
|
|
|
|
|
24
|
|
|
def __setattr__(self, name, value): |
|
25
|
|
|
if name.startswith("__") or name.startswith("_ContextProxy__"): |
|
26
|
|
|
return object.__setattr__(self, name, value) |
|
27
|
|
|
|
|
28
|
|
|
registry = getUtility(IRegistry) |
|
29
|
|
|
for interface in self.__interfaces: |
|
30
|
|
|
proxy = registry.forInterface(interface) |
|
31
|
|
|
try: |
|
32
|
|
|
getattr(proxy, name) |
|
33
|
|
|
except AttributeError: |
|
34
|
|
|
pass |
|
35
|
|
|
else: |
|
36
|
|
|
return setattr(proxy, name, value) |
|
37
|
|
|
raise AttributeError(name) |
|
38
|
|
|
|
|
39
|
|
|
def __getattr__(self, name): |
|
40
|
|
|
if name.startswith("__") or name.startswith("_ContextProxy__"): |
|
41
|
|
|
return object.__getattr__(self, name) |
|
42
|
|
|
|
|
43
|
|
|
registry = getUtility(IRegistry) |
|
44
|
|
|
for interface in self.__interfaces: |
|
45
|
|
|
proxy = registry.forInterface(interface) |
|
46
|
|
|
try: |
|
47
|
|
|
return getattr(proxy, name) |
|
48
|
|
|
except AttributeError: |
|
49
|
|
|
pass |
|
50
|
|
|
raise AttributeError(name) |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
class SenaiteRegistryControlPanelForm(RegistryEditForm): |
|
54
|
|
|
schema = ISenaiteRegistry |
|
55
|
|
|
label = _("SENAITE Registry") |
|
56
|
|
|
|
|
57
|
|
|
def getContent(self): |
|
58
|
|
|
interfaces = [self.schema] |
|
59
|
|
|
interfaces.extend(self.additionalSchemata) |
|
60
|
|
|
return ContextProxy(interfaces) |
|
61
|
|
|
|
|
62
|
|
|
@property |
|
63
|
|
|
def additionalSchemata(self): |
|
64
|
|
|
for interface in get_registry_interfaces(): |
|
65
|
|
|
yield interface |
|
66
|
|
|
|
|
67
|
|
|
def updateFields(self): |
|
68
|
|
|
super(SenaiteRegistryControlPanelForm, self).updateFields() |
|
69
|
|
|
|
|
70
|
|
|
def updateWidgets(self): |
|
71
|
|
|
super(SenaiteRegistryControlPanelForm, self).updateWidgets() |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
SenaiteRegistryControlPanelView = layout.wrap_form( |
|
75
|
|
|
SenaiteRegistryControlPanelForm, ControlPanelFormWrapper) |
|
76
|
|
|
|