Updated base forms prefix and ID getter
authorThierry Florac <thierry.florac@onf.fr>
Wed, 11 Apr 2018 11:04:19 +0200
changeset 96 777ba7b212fe
parent 95 aafae25003ba
child 97 fe1785bdc9d7
Updated base forms prefix and ID getter
src/pyams_form/form.py
src/pyams_form/templates/inner-form.pt
--- a/src/pyams_form/form.py	Wed Apr 11 11:02:32 2018 +0200
+++ b/src/pyams_form/form.py	Wed Apr 11 11:04:19 2018 +0200
@@ -26,7 +26,7 @@
 from pyams_i18n.interfaces import II18n
 from pyams_skin.interfaces import IDialog, ISkinnable, IContentTitle
 from pyams_template.interfaces import IContentTemplate, ILayoutTemplate
-from pyams_utils.interfaces import FORBIDDEN_PERMISSION
+from pyams_utils.interfaces import FORBIDDEN_PERMISSION, ICacheKeyValue
 from pyramid_chameleon.interfaces import IChameleonTranslate
 from z3c.form.interfaces import DISPLAY_MODE, IErrorViewSnippet, IMultipleErrors
 from zope.publisher.interfaces.browser import IBrowserRequest
@@ -62,6 +62,10 @@
 class BaseForm(GroupsBasedForm, Form):
     """Base form class"""
 
+    @property
+    def id(self):
+        return '{0}_{1}'.format(super(BaseForm, self).id, ICacheKeyValue(self.context))
+
     layout = None
     layer = IFormLayer
 
@@ -304,6 +308,8 @@
 class AddForm(AJAXForm, BaseAddForm):
     """Add form base class"""
 
+    prefix = 'add_form.'
+
     buttons = Buttons(IAddFormButtons)
 
     legend = _("Add form")
@@ -391,8 +397,10 @@
         if output:
             return output
         else:
-            return {'status': 'reload',
-                    'location': self.nextURL()}
+            return {
+                'status': 'reload',
+                'location': self.nextURL()
+            }
 
 
 @implementer(IDialog)
@@ -409,10 +417,6 @@
 
     css_class = 'inner'
 
-    @property
-    def id(self):
-        return self.__class__.__name__
-
     buttons = Buttons(Interface)
 
     def __init__(self, context, request, view=None):
@@ -539,10 +543,6 @@
 
     css_class = 'inner'
 
-    @property
-    def id(self):
-        return self.__class__.__name__
-
     buttons = Buttons(Interface)
 
     def __init__(self, context, request, view=None):
@@ -575,10 +575,6 @@
 
     css_class = 'inner'
 
-    @property
-    def id(self):
-        return self.__class__.__name__
-
     buttons = Buttons(Interface)
 
     def __init__(self, context, request, view=None):
--- a/src/pyams_form/templates/inner-form.pt	Wed Apr 11 11:02:32 2018 +0200
+++ b/src/pyams_form/templates/inner-form.pt	Wed Apr 11 11:04:19 2018 +0200
@@ -1,7 +1,6 @@
 <div class="no-padding"
-	 tal:define="content_name (getattr(view.getContent(), '__name__', None) or 'noname').replace('++', '');"
 	 tal:attributes="class string:${view.css_class} ${view.padding_class | default};
-					 id string:${context.__class__.__name__}_${content_name}_${view.id};">
+					 id view.id;">
 	<div tal:define="prefix provider:form_prefix"
 		 tal:replace="structure prefix">Form prefix</div>
 	<form method="post"