From: richard Date: Tue, 24 Jun 2003 04:52:26 +0000 (+0000) Subject: fix HTML file detection (hence history xref linking) (sf bug 741478) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fbaf2e7be21ea90da55d9806d4e86930de2a1b0a;p=roundup.git fix HTML file detection (hence history xref linking) (sf bug 741478) git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1763 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index 4a2fa65..8724ab0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -10,6 +10,7 @@ are given with the most recent entry first. - fix :required ordering problem (sf bug 740214) - audit some user properties for valid values (roles, address) (sf bugs 742968 and 739653) +- fix HTML file detection (hence history xref linking) (sf bug 741478) 2003-06-10 0.6.0b3 diff --git a/roundup/cgi/templating.py b/roundup/cgi/templating.py index db1d8ae..f4707ad 100644 --- a/roundup/cgi/templating.py +++ b/roundup/cgi/templating.py @@ -25,6 +25,46 @@ from roundup.cgi import ZTUtils class NoTemplate(Exception): pass +def find_template(dir, name, extension): + ''' Find a template in the nominated dir + ''' + # find the source + if extension: + filename = '%s.%s'%(name, extension) + else: + filename = name + + # try old-style + src = os.path.join(dir, filename) + if os.path.exists(src): + return (src, filename) + + # try with a .html extension (new-style) + filename = filename + '.html' + src = os.path.join(dir, filename) + if os.path.exists(src): + return (src, filename) + + # no extension == no generic template is possible + if not extension: + raise NoTemplate, 'Template file "%s" doesn\'t exist'%name + + # try for a _generic template + generic = '_generic.%s'%extension + src = os.path.join(dir, generic) + if os.path.exists(src): + return (src, generic) + + # finally, try _generic.html + generic = filename + '.html' + src = os.path.join(dir, generic) + if os.path.exists(src): + return (src, generic) + + raise NoTemplate, 'No template file exists for templating "%s" '\ + 'with template "%s" (neither "%s" nor "%s")'%(name, extension, + filename, generic) + class Templates: templates = {} @@ -59,33 +99,10 @@ class Templates: # split name name, extension = name.split('.') - # find the source, figure the time it was last modified - if extension: - filename = '%s.%s'%(name, extension) - else: - filename = name - - src = os.path.join(self.dir, filename) - if not os.path.exists(src): - filename = filename + '.html' - src = os.path.join(self.dir, filename) - if not os.path.exists(src): - if not extension: - raise NoTemplate, 'Template file "%s" doesn\'t exist'%name - - # try for a generic template - generic = '_generic.%s'%extension - src = os.path.join(self.dir, generic) - if not os.path.exists(src): - generic = '_generic.%s.html'%extension - src = os.path.join(self.dir, generic) - if not os.path.exists(src): - raise NoTemplate, 'No template file exists for '\ - 'templating "%s" with template "%s" (neither '\ - '"%s" nor "%s")'%(name, extension, filename, - generic) - filename = generic + # find the source + src, filename = find_template(self.dir, name, extension) + # has it changed? try: stime = os.stat(src)[os.path.stat.ST_MTIME] except os.error, error: @@ -564,9 +581,15 @@ class HTMLItem(HTMLPermissions): if (self._props.has_key(prop_n) and isinstance(self._props[prop_n], hyperdb.Link)): classname = self._props[prop_n].classname - if os.path.exists(os.path.join(self._db.config.TEMPLATES, classname + '.item')): - current[prop_n] = '%s'%(classname, - self._klass.get(self._nodeid, prop_n, None), current[prop_n]) + try: + find_template(self._db.config.TEMPLATES, + classname, 'item') + except NoTemplate: + pass + else: + id = self._klass.get(self._nodeid, prop_n, None) + current[prop_n] = '%s'%( + classname, id, current[prop_n]) for id, evt_date, user, action, args in history: date_s = str(evt_date.local(timezone)).replace("."," ")