app/soc/views/sponsor/profile.py
changeset 517 661ab830e921
parent 516 ec1dcd70b97e
child 518 d9d31d316a74
equal deleted inserted replaced
516:ec1dcd70b97e 517:661ab830e921
     1 #!/usr/bin/python2.5
       
     2 #
       
     3 # Copyright 2008 the Melange authors.
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #   http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 
       
    17 """Views for displaying public Sponsor profiles.
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21   '"Pawel Solyga" <pawel.solyga@gmail.com>',
       
    22   ]
       
    23 
       
    24 
       
    25 from soc.logic import out_of_band
       
    26 from soc.views import helper
       
    27 from soc.views import simple
       
    28 from soc.views.helper import decorators
       
    29 
       
    30 import soc.logic.models.sponsor
       
    31 import soc.models.sponsor as sponsor_model
       
    32 import soc.views.helper.responses
       
    33 import soc.views.helper.templates
       
    34 
       
    35 
       
    36 DEF_SPONSOR_PUBLIC_TMPL = 'soc/group/profile/public.html'
       
    37 
       
    38 @decorators.view
       
    39 def public(request, page_name=None, link_id=None, 
       
    40            template=DEF_SPONSOR_PUBLIC_TMPL):
       
    41   """How the "general public" sees the Sponsor profile.
       
    42 
       
    43   Args:
       
    44     request: the standard django request object.
       
    45     page_name: the page name displayed in templates as page and header title
       
    46     link_id: the Sponsor's site-unique "link_id" extracted from the URL
       
    47     template: the template path to use for rendering the template
       
    48 
       
    49   Returns:
       
    50     A subclass of django.http.HttpResponse with generated template.
       
    51   """
       
    52   # create default template context for use with any templates
       
    53   context = helper.responses.getUniversalContext(request)
       
    54   context['page_name'] = page_name
       
    55 
       
    56   try:
       
    57     link_id_sponsor = soc.logic.models.sponsor.logic.getIfFields(
       
    58         link_id=link_id)
       
    59   except out_of_band.ErrorResponse, error:
       
    60     # show custom 404 page when link ID doesn't exist in Datastore
       
    61     return simple.errorResponse(request, page_name, error, template, context)
       
    62 
       
    63   link_id_sponsor.description = \
       
    64       helper.templates.unescape(link_id_sponsor.description)
       
    65   
       
    66   context.update({'entity': link_id_sponsor,
       
    67                   'entity_type': sponsor_model.Sponsor.TYPE_NAME})
       
    68 
       
    69   return helper.responses.respond(request, template, context)