12 |
12 |
13 from pyramid.events import subscriber |
13 from pyramid.events import subscriber |
14 from zope.component.interfaces import ISite |
14 from zope.component.interfaces import ISite |
15 from zope.interface import implementer |
15 from zope.interface import implementer |
16 from zope.lifecycleevent.interfaces import IObjectAddedEvent |
16 from zope.lifecycleevent.interfaces import IObjectAddedEvent |
|
17 from zope.schema.fieldproperty import FieldProperty |
17 |
18 |
18 from pyams_content.component.paragraph import IParagraphFactorySettings |
19 from pyams_content.component.paragraph import IParagraphFactorySettings |
19 from pyams_content.shared.common.interfaces import ISharedContentFactory |
20 from pyams_content.shared.common.interfaces import ISharedContentFactory |
20 from pyams_content.shared.common.manager import SharedTool |
21 from pyams_content.shared.common.manager import SharedTool |
21 from pyams_content.shared.form import Form |
22 from pyams_content.shared.form import Form |
34 """Forms manager class""" |
35 """Forms manager class""" |
35 |
36 |
36 shared_content_type = FORM_CONTENT_TYPE |
37 shared_content_type = FORM_CONTENT_TYPE |
37 shared_content_menu = False |
38 shared_content_menu = False |
38 |
39 |
|
40 use_captcha = FieldProperty(IFormsManager['use_captcha']) |
|
41 default_captcha_client_key = FieldProperty(IFormsManager['default_captcha_client_key']) |
|
42 default_captcha_server_key = FieldProperty(IFormsManager['default_captcha_server_key']) |
|
43 use_proxy = FieldProperty(IFormsManager['use_proxy']) |
|
44 proxy_proto = FieldProperty(IFormsManager['proxy_proto']) |
|
45 proxy_host = FieldProperty(IFormsManager['proxy_host']) |
|
46 proxy_port = FieldProperty(IFormsManager['proxy_port']) |
|
47 proxy_username = FieldProperty(IFormsManager['proxy_username']) |
|
48 proxy_password = FieldProperty(IFormsManager['proxy_password']) |
|
49 proxy_only_from = FieldProperty(IFormsManager['proxy_only_from']) |
|
50 |
|
51 def get_captcha_settings(self): |
|
52 result = { |
|
53 'use_captcha': False, |
|
54 'client_key': None, |
|
55 'server_key': None |
|
56 } |
|
57 if self.use_captcha: |
|
58 result.update({ |
|
59 'use_captcha': True, |
|
60 'client_key': self.default_captcha_client_key, |
|
61 'server_key': self.default_captcha_server_key |
|
62 }) |
|
63 return result |
|
64 |
|
65 def get_proxy_url(self, request): |
|
66 if self.use_proxy: |
|
67 # check selected domains names |
|
68 if self.proxy_only_from: |
|
69 domains = map(str.strip, self.proxy_only_from.split(',')) |
|
70 if request.host not in domains: |
|
71 return None |
|
72 return '{}://{}{}:{}/'.format(self.proxy_proto, |
|
73 '{}{}{}@'.format(self.proxy_username, |
|
74 ':' if self.proxy_password else '', |
|
75 self.proxy_password or '') |
|
76 if self.proxy_username else '', |
|
77 self.proxy_host, |
|
78 self.proxy_port) |
|
79 |
39 |
80 |
40 @utility_config(provides=IFormsManagerFactory) |
81 @utility_config(provides=IFormsManagerFactory) |
41 class FormsManagerFactory(object): |
82 class FormsManagerFactory(object): |
42 """Defautl forms manager factory""" |
83 """Defautl forms manager factory""" |
43 |
84 |