# HG changeset patch # User Todd Larsen # Date 1232481861 0 # Node ID b55c68d25b359468fdc05b0fe27dfd2cb4ab3b38 # Parent a086ff3888d323ab9e8eef0aee625086c296c71c Make getToSLink() an actual method for re-use by others. Uses the views.helper.redirects module to create the /document/show path, instead of hard-coding it as a format string. Patch by: Todd Larsen Review by: to-be-reviewed diff -r a086ff3888d3 -r b55c68d25b35 app/soc/views/models/presence.py --- a/app/soc/views/models/presence.py Tue Jan 20 19:40:41 2009 +0000 +++ b/app/soc/views/models/presence.py Tue Jan 20 20:04:21 2009 +0000 @@ -32,6 +32,7 @@ from soc.logic.models import document as document_logic from soc.views import helper from soc.views.helper import access +from soc.views.helper import redirects from soc.views.models import base import soc.models.presence @@ -115,7 +116,7 @@ class View(base.View): - """View methods for the Document model. + """View methods for the Presence model. """ def __init__(self, params=None): @@ -148,6 +149,22 @@ 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(). """ @@ -164,21 +181,7 @@ home_doc.content = helper.templates.unescape(home_doc.content) context['home_document'] = home_doc - try: - tos_doc = entity.tos - except db.Error: - tos_doc = None - - if tos_doc: - # TODO(tlarsen): This may not be the correct way to do this... Also, - # at some point, this needs to be a link to *all* of the various - # Terms of Service that might apply to the scope of this particular - # page (e.g. site-wide ToS, program ToS, group ToS, etc.). See: - # http://code.google.com/p/soc/issues/detail?id=153 - # So, this probably needs to be added to base.py, but these - # overridden _public() methods do not seem to call it. - context['tos_link'] = '/document/show/%s/%s' % ( - tos_doc.scope_path, tos_doc.link_id) + context['tos_link'] = self.getToSLink(entity) def _editGet(self, request, entity, form): """See base.View._editGet().