app/soc/views/simple.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sun, 12 Oct 2008 00:12:53 +0000
changeset 299 a1cc853a56e5
parent 295 651d9eabdef7
child 316 9efdc7bc3565
permissions -rw-r--r--
Refactor nearly all the soc.logic code to use the Base class Instead of having a lot of duplicate code, this patch aims to reduce this duplication by introducing a Base abstraction. Patch by: Sverre Rabbelier Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""Simple views that depend entirely on the template and context.
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
"""
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
__authors__ = [
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
  '"Todd Larsen" <tlarsen@google.com>',
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 139
diff changeset
    22
  '"Pawel Solyga" <pawel.solyga@gmail.com>',
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
  ]
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    25
from google.appengine.api import users
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
139
93a9a22a4c38 Add getAltResponseIfNotLoggedIn() and getAltResponseIfNotDeveloper() simple
Todd Larsen <tlarsen@google.com>
parents: 125
diff changeset
    27
from django.utils.translation import ugettext_lazy
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    29
from soc.logic import out_of_band
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
from soc.logic.site import id_user
270
7dd6d8347b56 Move helpers/template_helpers.py to helper/templates.py.
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    31
from soc.views import helper
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 270
diff changeset
    32
import soc.views.helper.responses
270
7dd6d8347b56 Move helpers/template_helpers.py to helper/templates.py.
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    33
import soc.views.helper.templates
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    34
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    35
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    36
def public(request, template='soc/base.html', link_name=None,
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    37
                         context=None):
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    38
  """A simple template view that expects a link_name extracted from the URL.
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    39
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
  Args:
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    41
    request: the standard Django HTTP request object
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
    template: the template to use for rendering the view (or a search list
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    43
      of templates)
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    44
    link_name: a site-unique "link_name" (usually extracted from the URL)
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
    context: the context dict supplied to the template, which is modified
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46
        (so supply a copy if such modification is not acceptable)
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    47
      link_name: the link_name parameter is added to the context
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    48
      link_name_user: if the link_name exists for a User, that User
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    49
        is added to the context
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    50
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    51
  Returns:
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
    A subclass of django.http.HttpResponse containing the generated page.
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
  """
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    54
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    55
  template = helper.templates.makeSiblingTemplatesList(template, 'public.html')
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    56
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    57
  if not context:
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    58
    context = helper.responses.getUniversalContext(request)
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    59
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
  try:
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    61
    if link_name:
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    62
      user = id_user.getUserFromLinkNameOrDie(link_name)
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    63
  except out_of_band.ErrorResponse, error:
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    64
    return errorResponse(request, error, template, context)
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    65
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    66
  context['link_name'] = link_name
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    67
  context['link_name_user'] = user
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    68
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 270
diff changeset
    69
  return helper.responses.respond(request, template, context)
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    70
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    71
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    72
DEF_ERROR_TMPL = 'soc/error.html'
122
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
    73
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    74
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    75
def errorResponse(request, error, template, context):
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    76
  """Displays an error page for an out_of_band.ErrorResponse exception.
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    77
  
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    78
  Args:
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    79
    request: the standard Django HTTP request object
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    80
    error: an out_of_band.ErrorResponse exception
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    81
    template: the "sibling" template (or a search list of such templates)
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    82
      from which to construct the error.html template name (or names)
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    83
    context: the context dict supplied to the template, which is modified
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    84
        (so supply a copy if such modification is not acceptable)
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    85
      error_message: the error message string from error.message
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    86
      error_status: error.response_args['status'], or None if a status code
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    87
        was not supplied to the ErrorResponse
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    88
  """
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    89
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    90
  if not context:
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    91
    context = helper.responses.getUniversalContext(request)
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
    92
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    93
  # make a list of possible "sibling" templates, then append a default
270
7dd6d8347b56 Move helpers/template_helpers.py to helper/templates.py.
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    94
  error_templates = helper.templates.makeSiblingTemplatesList(
125
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 123
diff changeset
    95
      template, 'error.html', default_template=DEF_ERROR_TMPL)
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    96
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    97
  context['error_status'] = error.response_args.get('status')
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    98
  context['error_message'] = error.message
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    99
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 270
diff changeset
   100
  return helper.responses.respond(request, error_templates, context=context,
119
50d8d58dcd7c Add soc.views.simple containing (initially) two simple template views.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   101
                                  response_args=error.response_args)
122
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   102
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   103
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   104
DEF_LOGIN_TMPL = 'soc/login.html'
139
93a9a22a4c38 Add getAltResponseIfNotLoggedIn() and getAltResponseIfNotDeveloper() simple
Todd Larsen <tlarsen@google.com>
parents: 125
diff changeset
   105
DEF_LOGIN_MSG_FMT = ugettext_lazy(
93a9a22a4c38 Add getAltResponseIfNotLoggedIn() and getAltResponseIfNotDeveloper() simple
Todd Larsen <tlarsen@google.com>
parents: 125
diff changeset
   106
  'Please <a href="%(sign_in)s">sign in</a> to continue.')
122
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   107
293
1edd01373e71 Add an access control module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 272
diff changeset
   108
def requestLogin(request, template, context=None, login_message_fmt=None):
122
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   109
  """Displays a login request page with custom message and login link.
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   110
  
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   111
  Args:
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   112
    request: the standard Django HTTP request object
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   113
    template: the "sibling" template (or a search list of such templates)
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   114
      from which to construct the login.html template name (or names)
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   115
    login_message_fmt: a custom message format string used to create a
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   116
      message displayed on the login page; the format string can contain
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   117
      named format specifiers for any of the keys in context, but should at
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   118
      least contain %(sign_in)s
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   119
    context: the context dict supplied to the template, which is modified
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   120
        (so supply a copy if such modification is not acceptable); 
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   121
      login_message: the caller can completely construct the message supplied
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   122
        to the login template in lieu of using login_message_fmt
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   123
  """
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
   124
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
   125
  if not context:
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 295
diff changeset
   126
    context = helper.responses.getUniversalContext(request)
122
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   127
  
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   128
  # make a list of possible "sibling" templates, then append a default
270
7dd6d8347b56 Move helpers/template_helpers.py to helper/templates.py.
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   129
  login_templates = helper.templates.makeSiblingTemplatesList(
125
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 123
diff changeset
   130
      template, 'login.html', default_template=DEF_LOGIN_TMPL)
122
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   131
  
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   132
  if not context.get('login_message'):
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   133
    if not login_message_fmt:
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   134
      login_message_fmt = DEF_LOGIN_MSG_FMT
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   135
    context['login_message'] = login_message_fmt % context  
95d0d954fe0b Add a public() convenience wrapper around templateWithLinkName() for the common
Todd Larsen <tlarsen@google.com>
parents: 119
diff changeset
   136
  
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 270
diff changeset
   137
  return helper.responses.respond(request, login_templates, context=context)
139
93a9a22a4c38 Add getAltResponseIfNotLoggedIn() and getAltResponseIfNotDeveloper() simple
Todd Larsen <tlarsen@google.com>
parents: 125
diff changeset
   138