# HG changeset patch # User Todd Larsen # Date 1219959055 0 # Node ID 26d86de677146793166dcb377232f86b035d11ca # Parent 4d9895fb15bcc0d8ce0de2ab316fa9bb9b519a6b Helpers for manipulating templates and template search paths. Patch by: Todd Larsen Review by: to-be-reviewed diff -r 4d9895fb15bc -r 26d86de67714 app/soc/views/helpers/template_helpers.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/views/helpers/template_helpers.py Thu Aug 28 21:30:55 2008 +0000 @@ -0,0 +1,46 @@ +#!/usr/bin/python2.5 +# +# Copyright 2008 the Melange authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Helpers for manipulating templates. +""" + +__authors__ = [ + '"Todd Larsen" ', + ] + + +def makeSiblingTemplatesList(templates, new_template_file): + """Converts template paths into a list of "sibling" templates. + + Args: + templates: search list of templates (or just a single template not in a + list) from which template paths will be extracted (discarding the final + template file name of each template) + new_template_file: new "sibling" template file to append to each extracted + template path + + Returns: + A list of potential "sibling" templates named by new_template_file located + in the paths of the templates in the supplied list. For example, from: + ['foo/bar/the_old_template.html', 'foo/the_old_template.html'] + to: + ['foo/bar/some_new_template.html', 'foo/some_new_template.html'] + """ + if not isinstance(templates, (list, tuple)): + templates = [templates] + + return [ + '%s/%s' % (t.rsplit('/', 1)[0], new_template_file) for t in templates]