[Mpuls-commits] r2732 - in base/trunk: . mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri May 21 20:06:14 CEST 2010


Author: bh
Date: 2010-05-21 20:06:12 +0200 (Fri, 21 May 2010)
New Revision: 2732

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/lib/renderer.py
Log:
* mpulsweb/lib/renderer.py (tag): Allow attribute names that
contain minus signs by converting underscored to minus signs in
attribute names.  Fortunately there are no attribute names in HTML
that use underscores.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-05-21 17:54:59 UTC (rev 2731)
+++ base/trunk/ChangeLog	2010-05-21 18:06:12 UTC (rev 2732)
@@ -1,5 +1,12 @@
 2010-05-21  Bernhard Herzog  <bh at intevation.de>
 
+	* mpulsweb/lib/renderer.py (tag): Allow attribute names that
+	contain minus signs by converting underscored to minus signs in
+	attribute names.  Fortunately there are no attribute names in HTML
+	that use underscores.
+
+2010-05-21  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/config/environment.py (load_environment): Add an
 	explicit configuration option for the template module directory:
 	mpuls.app.path.template_cache.  If that option is not given use

Modified: base/trunk/mpulsweb/lib/renderer.py
===================================================================
--- base/trunk/mpulsweb/lib/renderer.py	2010-05-21 17:54:59 UTC (rev 2731)
+++ base/trunk/mpulsweb/lib/renderer.py	2010-05-21 18:06:12 UTC (rev 2732)
@@ -99,6 +99,13 @@
     it is preset, so that e.g. the class attribute can be specified
     using the class_ keyword parameters.
 
+    A few attribute names are not valid Python identifiers because they
+    contain a minus-sign (e.g. accept-charset).  However, since there
+    are no attribute names that contain underscores, underscores in a
+    keyword argument will be converted to minus-signs to determine the
+    attribute name.  For instance the accept-charset attribute can be
+    given as accept_charset to this function.
+
     Examples:
     >>> from mpulsweb.lib.renderer import tag
     >>> tag("input", type="text", name="title", disabled=False)
@@ -109,6 +116,7 @@
     for name, value in attrs.items():
         if name.endswith("_"):
             name = name[:-1]
+        name = name.replace("_", "-")
         if name in _booleans:
             if value:
                 out.append(' %s="%s"' % (name, name))



More information about the Mpuls-commits mailing list