[Mpuls-commits] r4936 - in base/trunk: . mpulsweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon May 2 10:03:10 CEST 2011


Author: torsten
Date: 2011-05-02 10:03:06 +0200 (Mon, 02 May 2011)
New Revision: 4936

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/controllers/case.py
Log:
Issue2027: Use htmlfill to render page to create a new case. This will make the templte much more easy. The change should not affekt old behavior. Further added a new method _get_validator which can be overwritten to add a custom validator in specific application code.



Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2011-04-29 14:06:03 UTC (rev 4935)
+++ base/trunk/ChangeLog	2011-05-02 08:03:06 UTC (rev 4936)
@@ -1,3 +1,11 @@
+2011-05-02  Torsten Irländer <torsten.irlaender at intevation.de>
+
+	* mpulsweb/controllers/case.py: Issue2027: Use htmlfill to render page
+	to create a new case. This will make the templte much more easy. The
+	change should not affekt old behavior. Further added a new method
+	_get_validator which can be overwritten to add a custom validator in
+	specific application code.
+
 2011-04-29  Roland Geider  <roland.geider at intevation.de>
 	* mpulsweb/public/styles/all.css,
 	  mpulsweb/public/styles/print.css,

Modified: base/trunk/mpulsweb/controllers/case.py
===================================================================
--- base/trunk/mpulsweb/controllers/case.py	2011-04-29 14:06:03 UTC (rev 4935)
+++ base/trunk/mpulsweb/controllers/case.py	2011-05-02 08:03:06 UTC (rev 4936)
@@ -353,7 +353,12 @@
     @checkRole('cm')
     def new2(self):
         c.case = session.get('case')
-        return render('/casemanagement/new.mako')
+        form_errors = {}
+        form_defaults = c.case.getData() 
+        form = render('/casemanagement/new.mako')
+        return formencode.htmlfill.render(form, defaults=form_defaults,
+                                          auto_insert_errors=False,
+                                          errors=form_errors)
 
     def _add_custom_fields(self):
         '''This function should be overwritten in specific applications to add
@@ -361,6 +366,11 @@
         default this function returns an empty dictionary.'''
         return {}
 
+    def _get_validator(self):
+        '''This function should be overwritten in specific applications to add
+        a custom validator'''
+        return NewCaseForm()
+
     @checkRole('cm_ka')
     def newAction(self):
         # TODO: Use htmlfill here!
@@ -379,7 +389,7 @@
 
         # Or do we want to store the new case?
         elif request.params.has_key('save'):
-            validator = NewCaseForm()
+            validator = self._get_validator()
             try:
                 form_result = validator.to_python(request.params)
                 # Add custom fields to the form_result which are not part of
@@ -391,7 +401,11 @@
                 log.debug("Invalid form data: %r", error)
                 c.form_result = error.value
                 c.form_errors = error.error_dict or {}
-                return render('/casemanagement/new.mako')
+                form = render('/casemanagement/new.mako')
+                return formencode.htmlfill.render(form, 
+                                            defaults=c.form_result,
+                                            auto_insert_errors=False,
+                                            errors=c.form_errors)
 
         return self.select(str(case.id))
 



More information about the Mpuls-commits mailing list