app/soc/views/simple.py
changeset 361 465e4df617de
parent 358 843d83b87282
child 365 74dec172944e
equal deleted inserted replaced
360:5ad9cabb5892 361:465e4df617de
    32 
    32 
    33 import soc.views.helper.responses
    33 import soc.views.helper.responses
    34 import soc.views.helper.templates
    34 import soc.views.helper.templates
    35 
    35 
    36 
    36 
    37 def public(request, template='soc/base.html', link_name=None,
    37 DEF_PUBLIC_TMPL = 'soc/base.html'
    38            context=None, page=None):
    38 
       
    39 def public(request, page=None, template=DEF_PUBLIC_TMPL, link_name=None,
       
    40            context=None):
    39   """A simple template view that expects a link_name extracted from the URL.
    41   """A simple template view that expects a link_name extracted from the URL.
    40 
    42 
    41   Args:
    43   Args:
    42     request: the standard Django HTTP request object
    44     request: the standard Django HTTP request object
       
    45     page: a soc.logic.site.page.Page object which is abstraction that combines 
       
    46       a Django view with sidebar menu info
    43     template: the template to use for rendering the view (or a search list
    47     template: the template to use for rendering the view (or a search list
    44       of templates)
    48       of templates)
    45     link_name: a site-unique "link_name" (usually extracted from the URL)
    49     link_name: a site-unique "link_name" (usually extracted from the URL)
    46     context: the context dict supplied to the template, which is modified
    50     context: the context dict supplied to the template, which is modified
    47       (so supply a copy if such modification is not acceptable)
    51       (so supply a copy if such modification is not acceptable)
    48     link_name: the link_name parameter is added to the context
    52     link_name: the link_name parameter is added to the context
    49     link_name_user: if the link_name exists for a User, that User
    53     link_name_user: if the link_name exists for a User, that User
    50       is added to the context
    54       is added to the context
    51     page: a soc.logic.site.page.Page object which is abstraction that combines 
    55 
    52       a Django view with sidebar menu info
       
    53 
    56 
    54   Returns:
    57   Returns:
    55     A subclass of django.http.HttpResponse containing the generated page.
    58     A subclass of django.http.HttpResponse containing the generated page.
    56   """
    59   """
    57 
    60 
    62 
    65 
    63   try:
    66   try:
    64     if link_name:
    67     if link_name:
    65       user = id_user.getUserFromLinkNameOr404(link_name)
    68       user = id_user.getUserFromLinkNameOr404(link_name)
    66   except out_of_band.ErrorResponse, error:
    69   except out_of_band.ErrorResponse, error:
    67     return errorResponse(request, error, template, context, page)
    70     return errorResponse(request, page, error, template, context)
    68 
    71 
    69   context['link_name'] = link_name
    72   context['link_name'] = link_name
    70   context['link_name_user'] = user
    73   context['link_name_user'] = user
    71 
    74 
    72   return helper.responses.respond(request, template, context)
    75   return helper.responses.respond(request, template, context)
    73 
    76 
    74 
    77 
    75 DEF_ERROR_TMPL = 'soc/error.html'
    78 DEF_ERROR_TMPL = 'soc/error.html'
    76 
    79 
    77 
    80 def errorResponse(request, page, error, template, context):
    78 def errorResponse(request, error, template, context, page=None):
       
    79   """Displays an error page for an out_of_band.ErrorResponse exception.
    81   """Displays an error page for an out_of_band.ErrorResponse exception.
    80   
    82   
    81   Args:
    83   Args:
    82     request: the standard Django HTTP request object
    84     request: the standard Django HTTP request object
       
    85     page: a soc.logic.site.page.Page object which is abstraction that combines 
       
    86       a Django view with sidebar menu info
    83     error: an out_of_band.ErrorResponse exception
    87     error: an out_of_band.ErrorResponse exception
    84     template: the "sibling" template (or a search list of such templates)
    88     template: the "sibling" template (or a search list of such templates)
    85       from which to construct the error.html template name (or names)
    89       from which to construct the error.html template name (or names)
    86     context: the context dict supplied to the template, which is modified
    90     context: the context dict supplied to the template, which is modified
    87       (so supply a copy if such modification is not acceptable)
    91       (so supply a copy if such modification is not acceptable)
    88     error_message: the error message string from error.message
    92     error_message: the error message string from error.message
    89     error_status: error.response_args['status'], or None if a status code
    93     error_status: error.response_args['status'], or None if a status code
    90       was not supplied to the ErrorResponse
    94       was not supplied to the ErrorResponse
    91     page: a soc.logic.site.page.Page object which is abstraction that combines 
    95 
    92       a Django view with sidebar menu info
       
    93   """
    96   """
    94 
    97 
    95   if not context:
    98   if not context:
    96     context = helper.responses.getUniversalContext(request)
    99     context = helper.responses.getUniversalContext(request)
    97 
   100 
   108 
   111 
   109 DEF_LOGIN_TMPL = 'soc/login.html'
   112 DEF_LOGIN_TMPL = 'soc/login.html'
   110 DEF_LOGIN_MSG_FMT = ugettext_lazy(
   113 DEF_LOGIN_MSG_FMT = ugettext_lazy(
   111   'Please <a href="%(sign_in)s">sign in</a> to continue.')
   114   'Please <a href="%(sign_in)s">sign in</a> to continue.')
   112 
   115 
   113 def requestLogin(request, template, context=None, login_message_fmt=None,
   116 def requestLogin(request, page, template, context=None, login_message_fmt=None):
   114                  page=None):
       
   115   """Displays a login request page with custom message and login link.
   117   """Displays a login request page with custom message and login link.
   116   
   118   
   117   Args:
   119   Args:
   118     request: the standard Django HTTP request object
   120     request: the standard Django HTTP request object
       
   121     page: a soc.logic.site.page.Page object which is abstraction that combines 
       
   122       a Django view with sidebar menu info
   119     template: the "sibling" template (or a search list of such templates)
   123     template: the "sibling" template (or a search list of such templates)
   120       from which to construct the login.html template name (or names)
   124       from which to construct the login.html template name (or names)
   121     login_message_fmt: a custom message format string used to create a
   125     login_message_fmt: a custom message format string used to create a
   122       message displayed on the login page; the format string can contain
   126       message displayed on the login page; the format string can contain
   123       named format specifiers for any of the keys in context, but should at
   127       named format specifiers for any of the keys in context, but should at
   124       least contain %(sign_in)s
   128       least contain %(sign_in)s
   125     context: the context dict supplied to the template, which is modified
   129     context: the context dict supplied to the template, which is modified
   126       (so supply a copy if such modification is not acceptable)
   130       (so supply a copy if such modification is not acceptable)
   127     login_message: the caller can completely construct the message supplied
   131     login_message: the caller can completely construct the message supplied
   128       to the login template in lieu of using login_message_fmt
   132       to the login template in lieu of using login_message_fmt
   129     page: a soc.logic.site.page.Page object which is abstraction that combines 
   133 
   130       a Django view with sidebar menu info
       
   131   """
   134   """
   132 
   135 
   133   if not context:
   136   if not context:
   134     context = helper.responses.getUniversalContext(request)
   137     context = helper.responses.getUniversalContext(request)
   135   
   138