[8057] | 1 | ## $Id: zcml.py 18083 2025-06-07 02:06:59Z uli $ |
---|
[7576] | 2 | ## |
---|
[8057] | 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
[7576] | 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
[8057] | 8 | ## |
---|
[7576] | 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
[8057] | 13 | ## |
---|
[7576] | 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
| 18 | from zope.component.zcml import handler |
---|
[18083] | 19 | from waeup.kofa.interfaces import IDataCenterConfig, IReCaptchaConfig |
---|
[7576] | 20 | |
---|
| 21 | def data_center_conf(context, path): |
---|
| 22 | """Handler for ZCML ``datacenter`` directive. |
---|
| 23 | |
---|
| 24 | Registers a global utility under IDataCenterConfig and containing |
---|
| 25 | a dictionary with (currently) only one entry: `path`. |
---|
| 26 | |
---|
| 27 | The directive can be put into site.zcml like this: |
---|
| 28 | |
---|
| 29 | - Add to the header: |
---|
[7811] | 30 | ``xmlns:kofa="http://namespaces.waeup.org/kofa"`` |
---|
[7576] | 31 | |
---|
[7811] | 32 | - Then, after including waeup.kofa: |
---|
| 33 | ``<kofa:datacenter path="some/existing/file/path" />`` |
---|
[7576] | 34 | |
---|
| 35 | In a running instance (where some directive like above was |
---|
| 36 | processed during startup), one can then ask for the |
---|
| 37 | IDataCenterConfig utility: |
---|
| 38 | |
---|
[7811] | 39 | >>> from waeup.kofa.interfaces import IDataCenterConfig |
---|
[7576] | 40 | >>> from zope.component import getUtility |
---|
| 41 | >>> getUtility(IDataCenterConfig) |
---|
| 42 | {'path': 'some/existing/file/path'} |
---|
| 43 | |
---|
| 44 | """ |
---|
| 45 | context.action( |
---|
| 46 | discriminator = ('utility', IDataCenterConfig, ''), |
---|
| 47 | callable = handler, |
---|
| 48 | args = ('registerUtility', |
---|
| 49 | {'path':path}, IDataCenterConfig, '') |
---|
| 50 | ) |
---|
[18083] | 51 | |
---|
| 52 | |
---|
| 53 | def recaptcha_conf(context, public_key, private_key, hostname, min_score): |
---|
| 54 | """Handler for ZCML ``recaptcha`` directive. |
---|
| 55 | |
---|
| 56 | Registers a global utility under IReCaptchaConfig and containing a |
---|
| 57 | dictionary with entries: `enabled`, `public_key`, `private__key` and `url`. |
---|
| 58 | |
---|
| 59 | The directive can be put into site.zcml like this: |
---|
| 60 | |
---|
| 61 | - Add to the header: |
---|
| 62 | ``xmlns:kofa="http://namespaces.waeup.org/kofa"`` |
---|
| 63 | |
---|
| 64 | - Then, after including waeup.kofa: |
---|
| 65 | ``<kofa:recaptcha |
---|
| 66 | public_key="<YOUR_PUBKEY_HERE>" |
---|
| 67 | private_key="<YOUR_PRIVKEY_HERE>" |
---|
| 68 | hostname="mysite.com" |
---|
| 69 | min_score="0.7" |
---|
| 70 | />`` |
---|
| 71 | |
---|
| 72 | In a running instance (where some directive like above was |
---|
| 73 | processed during startup), one can then ask for the |
---|
| 74 | IReCaptchaConfig utility: |
---|
| 75 | |
---|
| 76 | >>> from waeup.kofa.interfaces import IReCaptchaConfig |
---|
| 77 | >>> from zope.component import getUtility |
---|
| 78 | >>> getUtility(IRecaptchaConfig) |
---|
| 79 | {'enabled': False, |
---|
| 80 | 'public_key': '<GOOGLE_SITEKEY', |
---|
| 81 | 'private_key': 'GOOGLE_PRIVATE_SITE_KEY', |
---|
| 82 | 'hostname': 'mydomain.com' |
---|
| 83 | 'min_score': Decimal(0.7)} |
---|
| 84 | |
---|
| 85 | """ |
---|
| 86 | context.action( |
---|
| 87 | discriminator = ('utility', IReCaptchaConfig, ''), |
---|
| 88 | callable = handler, |
---|
| 89 | args = ('registerUtility', |
---|
| 90 | { |
---|
| 91 | 'public_key': public_key, |
---|
| 92 | 'private_key': private_key, |
---|
| 93 | 'hostname': hostname, |
---|
| 94 | 'min_score': min_score |
---|
| 95 | }, IReCaptchaConfig, '') |
---|
| 96 | ) |
---|