14 |
14 |
15 |
15 |
16 # import standard library |
16 # import standard library |
17 |
17 |
18 # import interfaces |
18 # import interfaces |
19 from pyams_content.component.links.interfaces import ILinkContainerTarget |
19 from pyams_content.shared.form.interfaces import IWfForm, IForm, FORM_CONTENT_TYPE, FORM_CONTENT_NAME, \ |
20 from pyams_content.shared.form.interfaces import IWfForm, IForm, FORM_CONTENT_TYPE, FORM_CONTENT_NAME |
20 IFormFieldContainerTarget, IFormHandler |
21 |
21 |
22 # import packages |
22 # import packages |
23 from pyams_content.shared.common import WfSharedContent, register_content_type, SharedContent |
23 from pyams_content.shared.common import WfSharedContent, register_content_type, SharedContent |
24 from zope.interface import implementer |
24 from zope.component.globalregistry import getGlobalSiteManager |
|
25 from zope.interface import implementer, alsoProvides, noLongerProvides |
25 from zope.schema.fieldproperty import FieldProperty |
26 from zope.schema.fieldproperty import FieldProperty |
26 |
27 |
27 |
28 |
28 @implementer(IWfForm, ILinkContainerTarget) |
29 @implementer(IWfForm, IFormFieldContainerTarget) |
29 class WfForm(WfSharedContent): |
30 class WfForm(WfSharedContent): |
30 """Base form""" |
31 """Base form""" |
31 |
32 |
32 content_type = FORM_CONTENT_TYPE |
33 content_type = FORM_CONTENT_TYPE |
33 content_name = FORM_CONTENT_NAME |
34 content_name = FORM_CONTENT_NAME |
|
35 |
|
36 user_title = FieldProperty(IWfForm['user_title']) |
|
37 header = FieldProperty(IWfForm['header']) |
|
38 _handler = FieldProperty(IWfForm['handler']) |
|
39 auth_only = FieldProperty(IWfForm['auth_only']) |
|
40 use_captcha = FieldProperty(IWfForm['use_captcha']) |
|
41 submit_label = FieldProperty(IWfForm['submit_label']) |
|
42 |
|
43 @property |
|
44 def handler(self): |
|
45 return self._handler |
|
46 |
|
47 @handler.setter |
|
48 def handler(self, value): |
|
49 old_handler = self._handler |
|
50 if value == old_handler: |
|
51 return |
|
52 if old_handler is not None: |
|
53 handler = self.query_handler(old_handler) |
|
54 if (handler is not None) and handler.target_interface: |
|
55 noLongerProvides(self, handler.target_interface) |
|
56 if value is not None: |
|
57 handler = self.query_handler(value) |
|
58 if (handler is not None) and handler.target_interface: |
|
59 alsoProvides(self, handler.target_interface) |
|
60 self._handler = value |
|
61 |
|
62 def query_handler(self, handler=None): |
|
63 if handler is None: |
|
64 handler = self._handler |
|
65 if handler: |
|
66 registry = getGlobalSiteManager() |
|
67 return registry.queryUtility(IFormHandler, name=handler) |
34 |
68 |
35 register_content_type(WfForm) |
69 register_content_type(WfForm) |
36 |
70 |
37 |
71 |
38 @implementer(IForm) |
72 @implementer(IForm) |