Move getToSLink() to soc.views.helper.redirects.getToSRedirect().
Fixes a circular import problem that prevented the site-wide ToS link from
being displayed by checkAgreesToSiteToS(). This is now completely implemented.
Patch by: Todd Larsen
Review by: to-be-reviewed
--- a/app/soc/views/helper/access.py Wed Jan 21 21:41:36 2009 +0000
+++ b/app/soc/views/helper/access.py Wed Jan 21 22:21:40 2009 +0000
@@ -41,9 +41,11 @@
from soc.logic.models.host import logic as host_logic
from soc.logic.models.notification import logic as notification_logic
from soc.logic.models.request import logic as request_logic
+from soc.logic.models.site import logic as site_logic
from soc.logic.models.user import logic as user_logic
from soc.views import helper
from soc.views import out_of_band
+from soc.views.helper import redirects
DEF_NO_USER_LOGIN_MSG_FMT = ugettext_lazy(
@@ -206,7 +208,7 @@
# Would not reach this point of site-wide ToS did not exist, since
# agreesToSiteToS() call above always returns True if no ToS is in effect.
login_msg_fmt = DEF_AGREE_TO_TOS_MSG_FMT % {
- 'tos_link': 'TODO(tlarsen): fix circular import first to make this work'}
+ 'tos_link': redirects.getToSRedirect(site_logic.getSingleton())}
raise out_of_band.LoginRequest(message_fmt=login_msg_fmt)
--- a/app/soc/views/helper/redirects.py Wed Jan 21 21:41:36 2009 +0000
+++ b/app/soc/views/helper/redirects.py Wed Jan 21 22:21:40 2009 +0000
@@ -22,6 +22,9 @@
]
+from google.appengine.ext import db
+
+
def getInviteRedirect(entity, params):
"""Returns the invitation redirect for the specified entity.
"""
@@ -99,3 +102,22 @@
return '/%s/applicant/%s' % (
params['url_name'], entity.link_id)
+
+def getToSRedirect(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
+
+ if not tos_doc:
+ return None
+
+ return getPublicRedirect(tos_doc, {'url_name': 'document'})
--- a/app/soc/views/helper/responses.py Wed Jan 21 21:41:36 2009 +0000
+++ b/app/soc/views/helper/responses.py Wed Jan 21 22:21:40 2009 +0000
@@ -118,7 +118,7 @@
if settings:
context['ga_tracking_num'] = settings.ga_tracking_num
- context['tos_link'] = getToSLink(settings)
+ context['tos_link'] = redirects.getToSRedirect(settings)
return context
@@ -172,23 +172,3 @@
return respond(request, sibling_templates, context=context,
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
-
- if not tos_doc:
- return None
-
- return redirects.getPublicRedirect(tos_doc, {'url_name': 'document'})
-
--- a/app/soc/views/models/user.py Wed Jan 21 21:41:36 2009 +0000
+++ b/app/soc/views/models/user.py Wed Jan 21 22:21:40 2009 +0000
@@ -32,7 +32,7 @@
from soc.logic.models.site import logic as site_logic
from soc.logic.models.user import logic as user_logic
from soc.views import helper
-from soc.views.helper import responses
+from soc.views.helper import redirects
from soc.views.models import base
import soc.models.linkable
@@ -167,7 +167,7 @@
def _getToSExampleText(self):
"""Returns example_text linking to site-wide ToS, or a warning message.
"""
- tos_link = responses.getToSLink(site_logic.getSingleton())
+ tos_link = redirects.getToSRedirect(site_logic.getSingleton())
if not tos_link:
return ('<div class="notice"> <i>No site-wide</i> Terms of'