app/soc/views/site/user/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 User profiles.
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21   '"Pawel Solyga" <pawel.solyga@gmail.com>',
       
    22   ]
       
    23 
       
    24 
       
    25 from soc.logic import models
       
    26 from soc.views import helper
       
    27 from soc.views.helper import access
       
    28 from soc.views.helper import decorators
       
    29 
       
    30 import soc.logic
       
    31 import soc.models.user
       
    32 import soc.views.helper.lists
       
    33 import soc.views.helper.responses
       
    34 import soc.views.out_of_band
       
    35 
       
    36 
       
    37 DEF_SITE_USER_LIST_ALL_TMPL = 'soc/models/list.html'
       
    38 
       
    39 @decorators.view
       
    40 def all(request, page_name=None, template=DEF_SITE_USER_LIST_ALL_TMPL):
       
    41   """Show a list of all Users (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   users = models.user.logic.getForLimitAndOffset(limit + 1, offset=offset)
       
    68 
       
    69   context['pagination_form'] = helper.lists.makePaginationForm(request, limit)
       
    70 
       
    71   list_templates = {
       
    72       'list_main': 'soc/list/list_main.html',
       
    73       'list_pagination': 'soc/list/list_pagination.html',
       
    74       'list_row': 'soc/user/list/user_row.html',
       
    75       'list_heading': 'soc/user/list/user_heading.html'
       
    76       }
       
    77 
       
    78   context = helper.lists.setList(
       
    79       request, context, users,
       
    80       offset=offset, limit=limit, list_templates=list_templates)
       
    81 
       
    82   return helper.responses.respond(request, template, context)