From 53a711152640acdbd6f6e15edc8fc965956b4e63 Mon Sep 17 00:00:00 2001 From: richard Date: Sat, 6 Dec 2003 00:00:54 +0000 Subject: [PATCH] Applied Stefan Seefeld's html4/xhtml patch with some changes. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@2019 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 2 + doc/customizing.txt | 16 ++++++- doc/index.txt | 2 +- roundup/cgi/templating.py | 85 ++++++++++++++++++++++++++----------- templates/classic/config.py | 7 ++- templates/minimal/config.py | 7 ++- 6 files changed, 90 insertions(+), 29 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index fd2a449..685ab70 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -21,6 +21,8 @@ Feature: 828963) - ignore incoming email with "Precedence: bulk" (sf patch 843489) - use HTTP 'Content-Length' header (modified sf patch 844577) +- HTML generated is now HTML4 (or optionally XHTML) compliant (sf feature + 814314 and sf patch 834620) Fixed: - mysql documentation fixed to note requirement of 4.0+ and InnoDB diff --git a/doc/customizing.txt b/doc/customizing.txt index 0136601..137ca79 100644 --- a/doc/customizing.txt +++ b/doc/customizing.txt @@ -2,7 +2,7 @@ Customising Roundup =================== -:Version: $Revision: 1.105 $ +:Version: $Revision: 1.106 $ .. This document borrows from the ZopeBook section on ZPT. The original is at: http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx @@ -180,6 +180,11 @@ The configuration variables available are: Default class to use in the mailgw if one isn't supplied in email subjects. To disable, comment out the variable below or leave it blank. +**HTML_VERSION** - ``'html4'`` or ``'xhtml'`` + HTML version to generate. The templates are html4 by default. If you + wish to make them xhtml, then you'll need to change this var to 'xhtml' + too so all auto-generated HTML is compliant. + The default config.py is given below - as you can see, the MAIL_DOMAIN must be edited before any interaction with the tracker is attempted.:: @@ -255,6 +260,11 @@ tracker is attempted.:: MAIL_DEFAULT_CLASS = 'issue' # use "issue" class by default #MAIL_DEFAULT_CLASS = '' # disable (or just comment the var out) + # HTML version to generate. The templates are html4 by default. If you + # wish to make them xhtml, then you'll need to change this var to 'xhtml' + # too so all auto-generated HTML is compliant. + HTML_VERSION = 'html4' # either 'html4' or 'xhtml' + # # SECURITY DEFINITIONS # @@ -1054,6 +1064,10 @@ returning. Default templates ----------------- +The default templates are html4 compliant. If you wish to change them to be +xhtml compliant, you'll need to change the ``HTML_VERSION`` configuration +variable in ``config.py`` to ``'xhtml'`` instead of ``'html4'``. + Most customisation of the web view can be done by modifying the templates in the tracker ``'html'`` directory. There are several types of files in there. The *minimal* template includes: diff --git a/doc/index.txt b/doc/index.txt index fac1c91..953ecf6 100644 --- a/doc/index.txt +++ b/doc/index.txt @@ -49,6 +49,7 @@ implement this system on their time. Thanks also to the many people on the mailing list, in the sourceforge project and those who just report bugs: +Thomas Arendsen Hein, Anthony Baxter, Cameron Blackwood, Jeff Blaine, @@ -66,7 +67,6 @@ Johannes Gijsbers, Gus Gollings, Dan Grassi, Engelbert Gruber, -Thomas Arendsen Hein, Juergen Hermann, Tobias Hunger, James Kew, diff --git a/roundup/cgi/templating.py b/roundup/cgi/templating.py index 537a1cb..6fa573e 100644 --- a/roundup/cgi/templating.py +++ b/roundup/cgi/templating.py @@ -24,6 +24,14 @@ from roundup.cgi.PageTemplates.Expressions import getEngine from roundup.cgi.TAL.TALInterpreter import TALInterpreter from roundup.cgi import ZTUtils +def input_html4(**attrs): + """Generate an 'input' (html4) element with given attributes""" + return ''%' '.join(['%s="%s"'%item for item in attrs.items()]) + +def input_xhtml(**attrs): + """Generate an 'input' (xhtml) element with given attributes""" + return ''%' '.join(['%s="%s"'%item for item in attrs.items()]) + class NoTemplate(Exception): pass @@ -295,6 +303,14 @@ class HTMLClass(HTMLPermissions): self._klass = self._db.getclass(self.classname) self._props = self._klass.getprops() + html_version = 'html4' + if hasattr(self._client.instance.config, 'HTML_VERSION'): + html_version = self._client.instance.config.HTML_VERSION + if html_version == 'xhtml': + self.input = input_xhtml + else: + self.input = input_html4 + def __repr__(self): return ''%(id(self), self.classname) @@ -478,8 +494,8 @@ class HTMLClass(HTMLPermissions): def submit(self, label="Submit New Entry"): ''' Generate a submit button (and action hidden element) ''' - return ' \n'\ - ' '%label + return self.input(type="hidden",name="@action",value="new") + '\n' + \ + self.input(type="submit",name="submit",value=label) def history(self): return 'New node - no history' @@ -556,8 +572,8 @@ class HTMLItem(HTMLPermissions): def submit(self, label="Submit Changes"): ''' Generate a submit button (and action hidden element) ''' - return ' \n'\ - ' '%label + return self.input(type="hidden",name="@action",value="edit") + '\n' + \ + self.input(type="submit",name="submit",value=label) def journal(self, direction='descending'): ''' Return a list of HTMLJournalEntry instances. @@ -844,6 +860,15 @@ class HTMLProperty: self._formname = '%s%s@%s'%(classname, nodeid, name) else: self._formname = name + + html_version = 'html4' + if hasattr(self._client.instance.config, 'HTML_VERSION'): + html_version = self._client.instance.config.HTML_VERSION + if html_version == 'xhtml': + self.input = input_xhtml + else: + self.input = input_html4 + def __repr__(self): return ''%(id(self), self._formname, self._prop, self._value) @@ -918,7 +943,7 @@ class StringHTMLProperty(HTMLProperty): else: value = cgi.escape(str(self._value)) value = '"'.join(value.split('"')) - return ''%(self._formname, value, size) + return self.input(name=self._formname,value=value,size=size) def multiline(self, escape=0, rows=5, cols=40): ''' Render a multiline form edit field for the property @@ -958,15 +983,15 @@ class PasswordHTMLProperty(HTMLProperty): def field(self, size = 30): ''' Render a form edit field for the property. ''' - return ''%(self._formname, size) + return self.input(type="password", name=self._formname, size=size) def confirm(self, size = 30): ''' Render a second form edit field for the property, used for confirmation that the user typed the password correctly. Generates a field with name "@confirm@name". ''' - return ''%( - self._formname, size) + return self.input(type="password", name="@confirm@%s"%self._formname, + size=size) class NumberHTMLProperty(HTMLProperty): def plain(self): @@ -982,7 +1007,7 @@ class NumberHTMLProperty(HTMLProperty): else: value = cgi.escape(str(self._value)) value = '"'.join(value.split('"')) - return ''%(self._formname, value, size) + return self.input(name=self._formname,value=value,size=size) def __int__(self): ''' Return an int of me @@ -1007,14 +1032,16 @@ class BooleanHTMLProperty(HTMLProperty): ''' Render a form edit field for the property ''' checked = self._value and "checked" or "" - s = 'Yes'%(self._formname, - checked) - if checked: - checked = "" + if self._value: + s = self.input(type="radio",name=self._formname,value="yes",checked="checked") + s += 'Yes' + s +=self.input(type="radio",name=self._formname,value="no") + s += 'No' else: - checked = "checked" - s += 'No'%(self._formname, - checked) + s = self.input(type="radio",name=self._formname,value="yes") + s += 'Yes' + s +=self.input(type="radio",name=self._formname,value="no",checked="checked") + s += 'No' return s class DateHTMLProperty(HTMLProperty): @@ -1042,7 +1069,7 @@ class DateHTMLProperty(HTMLProperty): else: value = cgi.escape(str(self._value.local(self._db.getUserTimezone()))) value = '"'.join(value.split('"')) - return ''%(self._formname, value, size) + return self.input(name=self._formname,value=value,size=size) def reldate(self, pretty=1): ''' Render the interval between the date and now. @@ -1099,7 +1126,7 @@ class IntervalHTMLProperty(HTMLProperty): else: value = cgi.escape(str(self._value)) value = '"'.join(value.split('"')) - return ''%(self._formname, value, size) + return self.input(name=self._formname,value=value,size=size) class LinkHTMLProperty(HTMLProperty): ''' Link HTMLProperty @@ -1155,7 +1182,7 @@ class LinkHTMLProperty(HTMLProperty): l = [''%(self._formname, size, value) + return self.input(name=self._formname,size=size,value=value) def menu(self, size=None, height=None, showid=0, additional=[], **conditions): @@ -1342,7 +1369,7 @@ class MultilinkHTMLProperty(HTMLProperty): # figure if this option is selected s = '' if optionid in value or option in value: - s = 'selected ' + s = 'selected="selected" ' # figure the label if showid: @@ -1451,6 +1478,14 @@ class HTMLRequest: # the special char to use for special vars self.special_char = '@' + html_version = 'html4' + if hasattr(self.client.instance.config, 'HTML_VERSION'): + html_version = self.client.instance.config.HTML_VERSION + if html_version == 'xhtml': + self.input = input_xhtml + else: + self.input = input_html4 + self._post_init() def _post_init(self): @@ -1603,7 +1638,7 @@ env: %(env)s ''' return the current index args as form elements ''' l = [] sc = self.special_char - s = '' + s = self.input(type="hidden",name="%s",value="%s") if columns and self.columns: l.append(s%(sc+'columns', ','.join(self.columns))) if sort and self.sort[1] is not None: diff --git a/templates/classic/config.py b/templates/classic/config.py index 8f9057d..e6f6133 100644 --- a/templates/classic/config.py +++ b/templates/classic/config.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: config.py,v 1.3 2003-04-24 07:19:59 richard Exp $ +# $Id: config.py,v 1.4 2003-12-06 00:00:54 richard Exp $ import os @@ -106,6 +106,11 @@ EMAIL_LEAVE_BODY_UNCHANGED = 'no' # either 'yes' or 'no' MAIL_DEFAULT_CLASS = 'issue' # use "issue" class by default #MAIL_DEFAULT_CLASS = '' # disable (or just comment the var out) +# HTML version to generate. The templates are html4 by default. If you +# wish to make them xhtml, then you'll need to change this var to 'xhtml' +# too so all auto-generated HTML is compliant. +HTML_VERSION = 'html4' # either 'html4' or 'xhtml' + # # SECURITY DEFINITIONS # diff --git a/templates/minimal/config.py b/templates/minimal/config.py index f2d3f67..a3ceeb6 100644 --- a/templates/minimal/config.py +++ b/templates/minimal/config.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: config.py,v 1.2 2003-04-24 07:20:00 richard Exp $ +# $Id: config.py,v 1.3 2003-12-06 00:00:54 richard Exp $ import os @@ -110,4 +110,9 @@ EMAIL_LEAVE_BODY_UNCHANGED = 'no' # either 'yes' or 'no' MAIL_DEFAULT_CLASS = 'issue' # use "issue" class by default #MAIL_DEFAULT_CLASS = '' # disable (or just comment the var out) +# HTML version to generate. The templates are html4 by default. If you +# wish to make them xhtml, then you'll need to change this var to 'xhtml' +# too so all auto-generated HTML is compliant. +HTML_VERSION = 'html4' # either 'html4' or 'xhtml' + # vim: set filetype=python ts=4 sw=4 et si -- 2.30.2