Set form's status correctly in "add_error" method
authorThierry Florac <tflorac@ulthar.net>
Tue, 17 Sep 2019 11:55:32 +0200
changeset 185 8030eca2abf3
parent 184 848706a5100d
child 186 ddd454de3d32
Set form's status correctly in "add_error" method
src/pyams_form/form.py
--- a/src/pyams_form/form.py	Wed Aug 28 18:06:20 2019 +0200
+++ b/src/pyams_form/form.py	Tue Sep 17 11:55:32 2019 +0200
@@ -207,7 +207,10 @@
         snippet.update()
         widget.error = snippet
         self.widgets.errors += (snippet,)
-        self.status = error.args[0]
+        translate = self.request.localizer.translate
+        if not self.status:
+            self.status = translate(self.formErrorsMessage)
+        self.status += '\n{0}'.format(translate(error.args[0]))
 
     def update_content(self, content, data):
         changes = applyChanges(self, content, data.get(self, data))
@@ -660,10 +663,10 @@
 
 @subscriber(IFormCreatedEvent, context_selector=ISkinnable)
 def handle_form_skin(event):
-    request = event.object.request
+    request = _request = event.object.request
     if isinstance(request, PyramidPublisherRequest):
-        request = request._request
-    skin = ISkinnable(event.object).get_skin(request)
+        _request = request._request
+    skin = ISkinnable(event.object).get_skin(_request)
     if skin is not None:
         apply_skin(request, skin)