A better way to add site-wide ToS link to *all* pages on the site.
getUniversalContext() already fetches a copy of the Site settings, so use that
to see if the site-wide ToS exist and produce a link.
Patch by: Todd Larsen
Review by: to-be-reviewed
--- a/app/soc/views/helper/responses.py Tue Jan 20 22:21:32 2009 +0000
+++ b/app/soc/views/helper/responses.py Tue Jan 20 22:30:21 2009 +0000
@@ -33,6 +33,7 @@
from soc.logic import system
from soc.logic.models import site
from soc.views import helper
+from soc.views.helper import redirects
from soc.views.helper import templates
from soc.views.sitemap import sidebar
@@ -116,7 +117,9 @@
if settings:
context['ga_tracking_num'] = settings.ga_tracking_num
-
+
+ context['tos_link'] = getToSLink(settings)
+
return context
@@ -168,4 +171,21 @@
context['message'] = error.message_fmt % context
return respond(request, sibling_templates, context=context,
- response_args=error.response_args)
\ No newline at end of file
+ response_args=error.response_args)
+
+def getToSLink(presence):
+ """Returns link to 'show' the ToS Document if it exists, None otherwise.
+
+ Args:
+ presence: Presence entity that may or may not have a tos property
+ """
+ if not presence:
+ return None
+
+ try:
+ tos_doc = presence.tos
+ except db.Error:
+ return None
+
+ return redirects.getPublicRedirect(tos_doc, {'url_name': 'document'})
+
--- a/app/soc/views/models/presence.py Tue Jan 20 22:21:32 2009 +0000
+++ b/app/soc/views/models/presence.py Tue Jan 20 22:30:21 2009 +0000
@@ -149,22 +149,6 @@
super(View, self).__init__(params=params)
- def getToSLink(self, entity):
- """Returns link to 'show' the ToS Document if it exists, None otherwise.
-
- Args:
- entity: Presence entity that may or may not have a tos property
- """
- if not entity:
- return None
-
- try:
- tos_doc = entity.tos
- except db.Error:
- return None
-
- return redirects.getPublicRedirect(tos_doc, {'url_name': 'document'})
-
def _public(self, request, entity, context):
"""See base.View._public().
"""
@@ -181,8 +165,6 @@
home_doc.content = helper.templates.unescape(home_doc.content)
context['home_document'] = home_doc
- context['tos_link'] = self.getToSLink(entity)
-
def _editGet(self, request, entity, form):
"""See base.View._editGet().
"""