[Mpuls-commits] r1899 - in wasko/branches/2.0: . mpulsweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Mar 5 11:33:54 CET 2010


Author: bh
Date: 2010-03-05 11:33:52 +0100 (Fri, 05 Mar 2010)
New Revision: 1899

Modified:
   wasko/branches/2.0/ChangeLog
   wasko/branches/2.0/mpulsweb/controllers/formularpage.py
Log:
* mpulsweb/controllers/formularpage.py
(prepare_htmlfill_defaults): New.  Prepare default values for
htmlfill.  Currently this only affects date objects which are
converted to strings using the format_date function.  Now date
fields that contain values that violate rules are shown in the
same format as other date fields again.
(get_rendered_page): Convert the defaults with
prepare_htmlfill_defaults before passing them to htmlfill


Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog	2010-03-05 09:57:38 UTC (rev 1898)
+++ wasko/branches/2.0/ChangeLog	2010-03-05 10:33:52 UTC (rev 1899)
@@ -1,5 +1,16 @@
 2010-03-05  Bernhard Herzog  <bh at intevation.de>
 
+	* mpulsweb/controllers/formularpage.py
+	(prepare_htmlfill_defaults): New.  Prepare default values for
+	htmlfill.  Currently this only affects date objects which are
+	converted to strings using the format_date function.  Now date
+	fields that contain values that violate rules are shown in the
+	same format as other date fields again.
+	(get_rendered_page): Convert the defaults with
+	prepare_htmlfill_defaults before passing them to htmlfill
+
+2010-03-05  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/lib/renderer.py (ViewRenderer._renderConditional):
 	Evaluate the conditional's expression and render the conditional
 	depending on its result.

Modified: wasko/branches/2.0/mpulsweb/controllers/formularpage.py
===================================================================
--- wasko/branches/2.0/mpulsweb/controllers/formularpage.py	2010-03-05 09:57:38 UTC (rev 1898)
+++ wasko/branches/2.0/mpulsweb/controllers/formularpage.py	2010-03-05 10:33:52 UTC (rev 1899)
@@ -3,6 +3,7 @@
 import logging
 import traceback
 from cgi import escape
+import datetime
 
 import formencode
 
@@ -20,6 +21,7 @@
 from mpulsweb.lib.base import BaseController, render
 from mpulsweb.lib.renderer import ViewRenderer, RepeatGroupRenderer, \
      ErrorRenderer, apply_hidden_booleans
+from mpulsweb.lib.helpers import dd_mm_YYYY as format_date
 
 
 log = logging.getLogger(__name__)
@@ -62,6 +64,26 @@
             result[i] = params[i]
     return result
 
+def prepare_htmlfill_defaults(defaults):
+    """Prepare default values for htmlfill.
+
+    The defaults parameter should be a dictionary mapping field names to
+    values.  The return value is a new dictionary containing the
+    converted defaults.
+
+    String values are passed through unchanged.  Date objects (instances
+    of datetime.date) are converted using the format_date function.
+    Other types are also passed through unchanged and it is assumed that
+    the default conversion to strings that htmlfill performs does the
+    right thing for these values.
+    """
+    converted = {}
+    for key, value in defaults.iteritems():
+        if isinstance(value, datetime.date):
+            value = format_date(value)
+        converted[key] = value
+    return converted
+
 def get_rendered_page(id):
     factory = InstanceFactory(g.formedTree, PostgresDBInterface())
     instance_tree = factory.loadInstanceTreeByIdentifier(
@@ -108,6 +130,7 @@
 
     # Currently values of the fields are set within the renderer.
     # Htmlfill is used to fill in the error values from the error items.
+    defaults = prepare_htmlfill_defaults(defaults)
     return formencode.htmlfill.render(form, defaults=defaults,
                                       errors=errors, auto_insert_errors=False,
                                       force_defaults=False)



More information about the Mpuls-commits mailing list