app/soc/views/site/sponsor/list.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 """Developer views for listing Sponsors profiles.
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21   '"Pawel Solyga" <pawel.solyga@gmail.com>',
       
    22   ]
       
    23 
       
    24 
       
    25 from soc.views import helper
       
    26 from soc.logic.models import sponsor
       
    27 from soc.views.helper import access
       
    28 from soc.views.helper import decorators
       
    29 
       
    30 import soc.logic
       
    31 import soc.models.sponsor as sponsor_model
       
    32 import soc.views.helper.lists
       
    33 import soc.views.helper.responses
       
    34 import soc.views.out_of_band
       
    35 
       
    36 
       
    37 DEF_SITE_SPONSOR_LIST_ALL_TMPL = 'soc/models/list.html'
       
    38 
       
    39 @decorators.view
       
    40 def all(request, page_name=None, template=DEF_SITE_SPONSOR_LIST_ALL_TMPL):
       
    41   """Show a list of all Sponsors (limit rows per page).
       
    42   
       
    43   Args:
       
    44     request: the standard Django HTTP request object
       
    45     page_name: the page name displayed in templates as page and header title
       
    46     template: the "sibling" template (or a search list of such templates)
       
    47       from which to construct an alternate template name (or names)
       
    48 
       
    49   Returns:
       
    50     A subclass of django.http.HttpResponse which either contains the form to
       
    51     be filled out, or a redirect to the correct view in the interface.
       
    52   """
       
    53 
       
    54   try:
       
    55     access.checkIsDeveloper(request)
       
    56   except  soc.views.out_of_band.AccessViolationResponse, alt_response:
       
    57     return alt_response.response()
       
    58 
       
    59   # create default template context for use with any templates
       
    60   context = helper.responses.getUniversalContext(request)
       
    61   context['page_name'] = page_name
       
    62 
       
    63   offset, limit = helper.lists.cleanListParameters(
       
    64       offset=request.GET.get('offset'), limit=request.GET.get('limit'))
       
    65   
       
    66   # Fetch one more to see if there should be a 'next' link
       
    67   sponsors = sponsor.logic.getForLimitAndOffset(limit=limit + 1,
       
    68                                                        offset=offset)
       
    69 
       
    70   context['pagination_form'] = helper.lists.makePaginationForm(request, limit)
       
    71   
       
    72   list_templates = {'list_main': 'soc/list/list_main.html',
       
    73                     'list_pagination': 'soc/list/list_pagination.html',
       
    74                     'list_row': 'soc/group/list/group_row.html',
       
    75                     'list_heading': 'soc/group/list/group_heading.html'}
       
    76                       
       
    77   context = helper.lists.setList(request, context, sponsors, 
       
    78                                  offset=offset, limit=limit, 
       
    79                                  list_templates=list_templates)
       
    80                                  
       
    81   context.update({'entity_type': sponsor_model.Sponsor.TYPE_NAME,
       
    82                   'entity_type_plural': sponsor_model.Sponsor.TYPE_NAME_PLURAL,
       
    83                   'entity_type_short': sponsor_model.Sponsor.TYPE_NAME_SHORT})
       
    84 
       
    85   return helper.responses.respond(request, template, context)