diff roundup/cgi/templating.py @ 6058:8fbcaac944e7

Different fix for displaying booleans properly in xhtml vs html Original patch was rendering input tags as xhtml <input .../> rather than html4/5 format as <input ...>.
author John Rouillard <rouilj@ieee.org>
date Fri, 17 Jan 2020 19:50:24 -0500
parents b6e56d096c58
children 3ada6a3f48e1
line wrap: on
line diff
--- a/roundup/cgi/templating.py	Fri Jan 17 10:54:03 2020 +0100
+++ b/roundup/cgi/templating.py	Fri Jan 17 19:50:24 2020 -0500
@@ -443,11 +443,10 @@
         <input required ..> not <input required="required" ...>
         The latter is xhtml. Recognize booleans by:
           value is None
-          value is the same as the attribute
-        Code can use either method to indicate a pure boolean.
+        Code can use None to indicate a pure boolean.
     '''
     return ' '.join(['%s="%s"'%(k,html_escape(str(v), True)) 
-                         if v != None and k != v else '%s'%(k)
+                         if v != None else '%s'%(k)
                          for k,v in sorted(attrs.items())])
 
 def xhtml_cgi_escape_attrs(**attrs):
@@ -457,8 +456,7 @@
            <input required="required" ...> not <input required ..>
         The latter is html4 or 5. Recognize booleans by:
           value is None
-          value is the same as the atribute
-        Code can use either method to indicate a pure boolean.
+        Code can use None to indicate a pure boolean.
     '''
     return ' '.join(['%s="%s"'%(k,html_escape(str(v), True))
                          if v != None else '%s="%s"'%(k,k)
@@ -480,11 +478,12 @@
         html_version = 'html4'
         if hasattr(self._client.instance.config, 'HTML_VERSION'):
             html_version = self._client.instance.config.HTML_VERSION
-        # HTML-4 allows attributes like required=required, so for now
-        # revert the change that optimizes this and breaks rendering of
-        # non-boolean attributes (like name="name").
-        self.input = input_xhtml
-        self.cgi_escape_attrs=xhtml_cgi_escape_attrs
+        if html_version == 'xhtml':
+            self.input = input_xhtml
+            self.cgi_escape_attrs=xhtml_cgi_escape_attrs
+        else:
+            self.input = input_html4
+            self.cgi_escape_attrs=html4_cgi_escape_attrs
         # self._context is used for translations.
         # will be initialized by the first call to .gettext()
         self._context = None

Roundup Issue Tracker: http://roundup-tracker.org/