app/soc/views/helper/responses.py
changeset 646 860e17e5118f
parent 586 a4a36b06a870
child 648 4f879defb15b
equal deleted inserted replaced
645:262b27ed23af 646:860e17e5118f
    31 from soc import release
    31 from soc import release
    32 from soc.logic import accounts
    32 from soc.logic import accounts
    33 from soc.logic import system
    33 from soc.logic import system
    34 from soc.logic.models import site
    34 from soc.logic.models import site
    35 from soc.views import helper
    35 from soc.views import helper
       
    36 from soc.views.helper import templates
    36 from soc.views.sitemap import sidebar
    37 from soc.views.sitemap import sidebar
    37 
    38 
    38 import soc.logic
    39 import soc.logic
    39 import soc.logic.models.user
    40 import soc.logic.models.user
    40 import soc.views.helper.requests
    41 import soc.views.helper.requests
   134     a Django HTTP redirect response pointing to the altered path.
   135     a Django HTTP redirect response pointing to the altered path.
   135   """
   136   """
   136   path = helper.requests.replaceSuffix(request.path, old_suffix, new_suffix,
   137   path = helper.requests.replaceSuffix(request.path, old_suffix, new_suffix,
   137                                        params=params)
   138                                        params=params)
   138   return http.HttpResponseRedirect(path)
   139   return http.HttpResponseRedirect(path)
       
   140 
       
   141 
       
   142 def errorResponse(self, error, request, template=None, context=None):
       
   143   """Creates an HTTP response from the soc.views.out_of_band.Error exception.
       
   144 
       
   145   Args:
       
   146     errror: a out_of_band.Error object
       
   147     request: a Django HTTP request
       
   148     template: the "sibling" template (or a search list of such templates)
       
   149       from which to construct the actual template name (or names)
       
   150     context: optional context dict supplied to the template, which is
       
   151       modified (so supply a copy if such modification is not acceptable)
       
   152   """
       
   153   if not context:
       
   154     context = error.context
       
   155 
       
   156   if not context:
       
   157     context = getUniversalContext(request)
       
   158 
       
   159   if not template:
       
   160     template = []
       
   161 
       
   162   # make a list of possible "sibling" templates, then append a default
       
   163   sibling_templates = templates.makeSiblingTemplatesList(template,
       
   164       error.TEMPLATE_NAME, default_template=error.DEF_TEMPLATE)
       
   165 
       
   166   context['status'] = error.response_args.get('status')
       
   167 
       
   168   if not context.get('message'):
       
   169     # supplied context did not explicitly override the message
       
   170     context['message'] = self.message_fmt % context
       
   171 
       
   172   return respond(request, sibling_templates, context=context,
       
   173                  response_args=error.response_args)