Move helpers/template_helpers.py to helper/templates.py.
authorTodd Larsen <tlarsen@google.com>
Fri, 03 Oct 2008 23:01:49 +0000
changeset 270 7dd6d8347b56
parent 269 0f1acc4c3e1e
child 271 01e90bb21b7e
Move helpers/template_helpers.py to helper/templates.py. Patch by: Todd Larsen Review by: to-be-reviewed
app/soc/views/docs/show.py
app/soc/views/helper/templates.py
app/soc/views/helpers/template_helpers.py
app/soc/views/simple.py
app/soc/views/site/home.py
app/soc/views/sponsor/profile.py
--- a/app/soc/views/docs/show.py	Fri Oct 03 22:17:05 2008 +0000
+++ b/app/soc/views/docs/show.py	Fri Oct 03 23:01:49 2008 +0000
@@ -29,8 +29,9 @@
 from soc.logic import document
 from soc.logic import out_of_band
 from soc.views import simple
+from soc.views import helper
+import soc.views.helper.templates
 from soc.views.helpers import response_helpers
-from soc.views.helpers import template_helpers
 
 
 DEF_DOCS_PUBLIC_TMPL = 'soc/docs/public.html'
@@ -69,7 +70,7 @@
     # show custom 404 page when Document path doesn't exist in Datastore
     return simple.errorResponse(request, error, template, context)
 
-  doc.content = template_helpers.unescape(doc.content)
+  doc.content = helper.templates.unescape(doc.content)
   context['document'] = doc
 
   return response_helpers.respond(request, template, context)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/views/helper/templates.py	Fri Oct 03 23:01:49 2008 +0000
@@ -0,0 +1,69 @@
+#!/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" <tlarsen@google.com>',
+  '"Pawel Solyga" <pawel.solyga@gmail.com>'
+  ]
+
+
+def makeSiblingTemplatesList(templates, new_template_file,
+                             default_template=None):
+  """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
+    default_template: a default template (or a list of them) to append to the
+      end of the generated "sibling" template paths; default is None
+ 
+  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]
+
+  if default_template is None:
+    default_template = []
+
+  if not isinstance(default_template, (list, tuple)):
+    default_template = [default_template]
+
+  sibling_templates = [
+    '%s/%s' % (t.rsplit('/', 1)[0], new_template_file) for t in templates]
+
+  return sibling_templates + default_template
+
+
+def unescape(html): 
+  """Returns the given HTML with ampersands, quotes and carets decoded.
+  """ 
+  if not isinstance(html, basestring): 
+    html = str(html) 
+  
+  html.replace('&#39;',"'").replace('&lt;', '<')
+  html.replace('&gt;', '>').replace('&quot;', '"').replace('&amp;', '&')
+  return html
--- a/app/soc/views/helpers/template_helpers.py	Fri Oct 03 22:17:05 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-#!/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" <tlarsen@google.com>',
-  '"Pawel Solyga" <pawel.solyga@gmail.com>'
-  ]
-
-
-def makeSiblingTemplatesList(templates, new_template_file,
-                             default_template=None):
-  """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
-    default_template: a default template (or a list of them) to append to the
-      end of the generated "sibling" template paths; default is None
- 
-  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]
-
-  if default_template is None:
-    default_template = []
-
-  if not isinstance(default_template, (list, tuple)):
-    default_template = [default_template]
-
-  sibling_templates = [
-    '%s/%s' % (t.rsplit('/', 1)[0], new_template_file) for t in templates]
-
-  return sibling_templates + default_template
-
-
-def unescape(html): 
-  """Returns the given HTML with ampersands, quotes and carets decoded.
-  """ 
-  if not isinstance(html, basestring): 
-    html = str(html) 
-  
-  html.replace('&#39;',"'").replace('&lt;', '<')
-  html.replace('&gt;', '>').replace('&quot;', '"').replace('&amp;', '&')
-  return html
--- a/app/soc/views/simple.py	Fri Oct 03 22:17:05 2008 +0000
+++ b/app/soc/views/simple.py	Fri Oct 03 23:01:49 2008 +0000
@@ -27,8 +27,9 @@
 
 from soc.logic import out_of_band
 from soc.logic.site import id_user
+from soc.views import helper
+import soc.views.helper.templates
 from soc.views.helpers import response_helpers
-from soc.views.helpers import template_helpers
 
 
 def templateWithLinkName(request,
@@ -74,7 +75,7 @@
   """
   return templateWithLinkName(
       request, linkname=linkname, context=context,
-      template=template_helpers.makeSiblingTemplatesList(
+      template=helper.templates.makeSiblingTemplatesList(
           template, 'public.html'))
 
 
@@ -97,7 +98,7 @@
   context = response_helpers.getUniversalContext(request, context=context)
   
   # make a list of possible "sibling" templates, then append a default
-  error_templates = template_helpers.makeSiblingTemplatesList(
+  error_templates = helper.templates.makeSiblingTemplatesList(
       template, 'error.html', default_template=DEF_ERROR_TMPL)
 
   context['error_status'] = error.response_args.get('status')
@@ -130,7 +131,7 @@
   context = response_helpers.getUniversalContext(request, context=context)
   
   # make a list of possible "sibling" templates, then append a default
-  login_templates = template_helpers.makeSiblingTemplatesList(
+  login_templates = helper.templates.makeSiblingTemplatesList(
       template, 'login.html', default_template=DEF_LOGIN_TMPL)
   
   if not context.get('login_message'):
--- a/app/soc/views/site/home.py	Fri Oct 03 22:17:05 2008 +0000
+++ b/app/soc/views/site/home.py	Fri Oct 03 23:01:49 2008 +0000
@@ -37,10 +37,11 @@
 from soc.logic import validate
 from soc.logic.site import id_user
 from soc.views import simple
+from soc.views import helper
+import soc.views.helper.templates
 from soc.views.helpers import custom_widgets
 from soc.views.helpers import forms_helpers
 from soc.views.helpers import response_helpers
-from soc.views.helpers import template_helpers
 
 import soc.models.site_settings
 import soc.models.document
@@ -113,7 +114,7 @@
     site_doc = site_settings.home
   
     if site_doc:
-      site_doc.content = template_helpers.unescape(site_doc.content)
+      site_doc.content = helper.templates.unescape(site_doc.content)
       context.update({'site_document': site_doc})
 
   return response_helpers.respond(request, template, context)
--- a/app/soc/views/sponsor/profile.py	Fri Oct 03 22:17:05 2008 +0000
+++ b/app/soc/views/sponsor/profile.py	Fri Oct 03 23:01:49 2008 +0000
@@ -25,8 +25,9 @@
 from soc.logic import out_of_band
 from soc.logic import sponsor
 from soc.views import simple
+from soc.views import helper
+import soc.views.helper.templates
 from soc.views.helpers import response_helpers
-from soc.views.helpers import template_helpers
 
 
 DEF_SPONSOR_PUBLIC_TMPL = 'soc/group/profile/public.html'
@@ -52,7 +53,7 @@
     return simple.errorResponse(request, error, template, context)
 
   linkname_sponsor.description = \
-      template_helpers.unescape(linkname_sponsor.description)
+      helper.templates.unescape(linkname_sponsor.description)
   
   context.update({'linkname_group': linkname_sponsor,
                   'group_type': 'Sponsor'})