Store initial widget name in basename attribute
authorThierry Florac <thierry.florac@onf.fr>
Thu, 27 Sep 2018 12:54:05 +0200
changeset 76 f1ddf2db6038
parent 75 947b23a2b868
child 77 64ec283e0969
Store initial widget name in basename attribute
src/pyams_i18n/widget/__init__.py
--- a/src/pyams_i18n/widget/__init__.py	Tue Sep 18 16:23:28 2018 +0200
+++ b/src/pyams_i18n/widget/__init__.py	Thu Sep 27 12:54:05 2018 +0200
@@ -15,26 +15,26 @@
 
 # import standard library
 
+from pyramid.decorator import reify
+from z3c.form.browser.widget import HTMLInputWidget
+from z3c.form.converter import BaseDataConverter
+from z3c.form.interfaces import IDataConverter, IErrorViewSnippet, IFieldWidget, IFormAware, IValidator, NO_VALUE
+from z3c.form.util import expandPrefix
+from z3c.form.widget import FieldWidget, Widget
+from zope.interface import alsoProvides, implementer_only
+from zope.schema import ValidationError
+
 # import interfaces
 from pyams_form.interfaces.form import IFormLayer
+# import packages
+from pyams_form.widget import SEOTextLineFieldWidget, widgettemplate_config
 from pyams_i18n.interfaces import II18nManager, INegotiator
-from pyams_i18n.interfaces.schema import II18nField, II18nTextLineField, II18nTextField, II18nFileField, II18nHTMLField
-from pyams_i18n.interfaces.widget import II18nWidget, II18nTextLineWidget, II18nTextWidget, II18nFileWidget, \
-    II18nHTMLWidget, II18nSEOTextLineWidget
-from z3c.form.interfaces import IDataConverter, IFieldWidget, NO_VALUE, IFormAware, IValidator, IErrorViewSnippet
-
-# import packages
-from pyams_form.widget import widgettemplate_config, SEOTextLineFieldWidget
+from pyams_i18n.interfaces.schema import II18nField, II18nFileField, II18nHTMLField, II18nTextField, II18nTextLineField
+from pyams_i18n.interfaces.widget import II18nFileWidget, II18nHTMLWidget, II18nSEOTextLineWidget, II18nTextLineWidget, \
+    II18nTextWidget, II18nWidget
 from pyams_utils.adapter import adapter_config
 from pyams_utils.registry import query_utility
 from pyams_utils.traversing import get_parent
-from pyramid.decorator import reify
-from z3c.form.browser.widget import HTMLInputWidget
-from z3c.form.converter import BaseDataConverter
-from z3c.form.util import expandPrefix
-from z3c.form.widget import Widget, FieldWidget
-from zope.interface import implementer_only, alsoProvides
-from zope.schema import ValidationError
 
 
 @adapter_config(context=(II18nField, II18nWidget), provides=IDataConverter)
@@ -105,9 +105,11 @@
             else:
                 widget = registry.queryMultiAdapter((self.field.value_type, self.request), IFieldWidget)
             if widget is not None:
-                prefix = expandPrefix(self.form.prefix) + expandPrefix(self.form.widgets.prefix) + expandPrefix(lang)
+                base_prefix = expandPrefix(self.form.prefix) + expandPrefix(self.form.widgets.prefix)
+                prefix = base_prefix + expandPrefix(lang)
                 name = self.field.value_type.__name__ = self.field.__name__
                 widget.mode = self.mode
+                widget.basename = base_prefix + name
                 widget.name = prefix + name
                 widget.id = widget.name.replace('.', '-')
                 if IFormAware.providedBy(self):