app/soc/views/site/user/list.py
author Todd Larsen <tlarsen@google.com>
Fri, 03 Oct 2008 17:21:41 +0000
changeset 265 3c2994f3b85f
parent 263 9b39d93b677f
child 266 3b47bfd4f1b3
permissions -rw-r--r--
List views should have a selectable pagination "page" length: http://code.google.com/p/soc/issues/detail?id=59 Patch by: Chen Lunpeng and Todd Larsen Review by: Augie Fackler Review URL: http://codereviews.googleopensourceprograms.com/1201
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
186
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     2
#
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     4
#
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     8
#
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    10
#
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    16
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    17
"""Developer views for listing User profiles.
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    18
"""
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    19
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    20
__authors__ = [
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    21
  '"Pawel Solyga" <pawel.solyga@gmail.com>',
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    22
  ]
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    23
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    24
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    25
from soc.logic.site import id_user
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    26
from soc.views import simple
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    27
from soc.views.helpers import list_helpers
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    28
from soc.views.helpers import response_helpers
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    29
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    30
import soc.models.user
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    31
263
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 233
diff changeset
    32
186
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    33
DEF_SITE_USER_LIST_ALL_TMPL = 'soc/site/user/list/all.html'
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    34
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    35
def all(request, template=DEF_SITE_USER_LIST_ALL_TMPL):
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    36
  """Show a list of all Users (limit rows per page).
233
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    37
  
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    38
  Args:
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    39
    request: the standard Django HTTP request object
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    40
    template: the "sibling" template (or a search list of such templates)
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    41
      from which to construct an alternate template name (or names)
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    42
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    43
  Returns:
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    44
    A subclass of django.http.HttpResponse which either contains the form to
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    45
    be filled out, or a redirect to the correct view in the interface.
186
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    46
  """
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    47
  # create default template context for use with any templates
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    48
  context = response_helpers.getUniversalContext(request)
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    49
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    50
  alt_response = simple.getAltResponseIfNotDeveloper(request,
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    51
                                                     context=context)
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    52
  if alt_response:
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    53
    return alt_response  
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    54
  
265
3c2994f3b85f List views should have a selectable pagination "page" length:
Todd Larsen <tlarsen@google.com>
parents: 263
diff changeset
    55
  offset, limit = list_helpers.cleanListParameters(
3c2994f3b85f List views should have a selectable pagination "page" length:
Todd Larsen <tlarsen@google.com>
parents: 263
diff changeset
    56
      offset=request.GET.get('offset'), limit=request.GET.get('limit'))
263
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 233
diff changeset
    57
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 233
diff changeset
    58
  # Fetch one more to see if there should be a 'next' link
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 233
diff changeset
    59
  users = id_user.getUsersForLimitAndOffset(limit + 1, offset=offset)
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 233
diff changeset
    60
265
3c2994f3b85f List views should have a selectable pagination "page" length:
Todd Larsen <tlarsen@google.com>
parents: 263
diff changeset
    61
  context['pagination_form'] = list_helpers.makePaginationForm(request, limit)
186
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    62
  
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    63
  list_templates = {'list_main': 'soc/list/list_main.html',
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    64
                    'list_pagination': 'soc/list/list_pagination.html',
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    65
                    'list_row': 'soc/site/user/list/user_row.html',
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    66
                    'list_heading': 'soc/site/user/list/user_heading.html'}
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    67
                      
232
7741d6b7ce7c Fix some style guide issues: keyword arguments are supposed to always be
Todd Larsen <tlarsen@google.com>
parents: 186
diff changeset
    68
  context = list_helpers.setList(
7741d6b7ce7c Fix some style guide issues: keyword arguments are supposed to always be
Todd Larsen <tlarsen@google.com>
parents: 186
diff changeset
    69
      request, context, users,
7741d6b7ce7c Fix some style guide issues: keyword arguments are supposed to always be
Todd Larsen <tlarsen@google.com>
parents: 186
diff changeset
    70
      offset=offset, limit=limit, list_templates=list_templates)
186
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    71
da76f08b1752 Add Users List Developer view which is available at /site/user/list. Add User list custom templates which are used with list_helpers. Add "Users List" link in base.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    72
  return response_helpers.respond(request, template, context)
263
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 233
diff changeset
    73