Added custom boolean values adapter to handle translations
authorThierry Florac <thierry.florac@onf.fr>
Mon, 15 Sep 2014 13:05:49 +0200
changeset 61 d2ad83a628a0
parent 60 006912c0dd67
child 62 2f2dadb6b993
Added custom boolean values adapter to handle translations
src/ztfy/myams/configure.zcml
src/ztfy/myams/terms.py
--- a/src/ztfy/myams/configure.zcml	Mon Sep 15 13:05:10 2014 +0200
+++ b/src/ztfy/myams/configure.zcml	Mon Sep 15 13:05:49 2014 +0200
@@ -94,6 +94,10 @@
 		permission="zope.View" />
 
 
+	<!-- Custom boolean terms factory -->
+	<adapter factory=".terms.BoolTerms" />
+
+
 	<!-- Exceptions views -->
 	<browser:page
 		name="error"
@@ -198,6 +202,13 @@
 		layer=".layer.MyAMSLayer" />
 
 
+	<z3c:widgetTemplate
+		mode="input"
+		template="templates/forms/radio-input.pt"
+		widget="z3c.form.interfaces.IRadioWidget"
+		layer=".layer.MyAMSLayer" />
+
+
 	<!-- Login forms -->
 	<z3c:pagelet
 		name="login.html"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ztfy/myams/terms.py	Mon Sep 15 13:05:49 2014 +0200
@@ -0,0 +1,43 @@
+### -*- coding: utf-8 -*- ####################################################
+##############################################################################
+#
+# Copyright (c) 2013 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+
+# import standard packages
+
+# import Zope3 interfaces
+from z3c.form.interfaces import IWidget, IBoolTerms
+from zope.schema.interfaces import IBool
+
+# import local interfaces
+from ztfy.myams.layer import MyAMSLayer
+
+# import Zope3 packages
+from z3c.form.term import BoolTerms as BaseBoolTerms
+from zope.component import adapts
+from zope.interface import implementsOnly, Interface
+
+# import local packages
+
+from ztfy.skin import _
+
+
+class BoolTerms(BaseBoolTerms):
+    """Default yes and no terms are used by default for IBool fields."""
+
+    adapts(Interface, MyAMSLayer, Interface, IBool, IWidget)
+    implementsOnly(IBoolTerms)
+
+    trueLabel = _('yes')
+    falseLabel = _('no')