app/soc/views/site/user/list.py
author Sverre Rabbelier <srabbelier@gmail.com>
Thu, 09 Oct 2008 23:48:20 +0000
changeset 294 1fdaab4a6ef2
parent 272 00cea07656c0
child 299 a1cc853a56e5
permissions -rw-r--r--
Refactor existing code to use the new access module Instead of ending up with many different ways to do access control, we end up having only one centralized place wher access control is done. Patch by: Sverre Rabbelier Reviewed by: Pawel Solyga, Augie Fackler, Todd Larsen Reviewed at: http://codereviews.googleopensourceprograms.com/1601 Review id: 1601
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
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 272
diff changeset
    25
from soc.logic.helper import access
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
    26
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
    27
from soc.views import simple
268
af1d7f48b361 Move helpers/list.py to helper/lists.py to avoid conflict with built-in type
Todd Larsen <tlarsen@google.com>
parents: 266
diff changeset
    28
from soc.views import helper
af1d7f48b361 Move helpers/list.py to helper/lists.py to avoid conflict with built-in type
Todd Larsen <tlarsen@google.com>
parents: 266
diff changeset
    29
import soc.views.helper.lists
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 268
diff changeset
    30
import soc.views.helper.responses
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
    31
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
    32
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
    33
263
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 233
diff changeset
    34
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
    35
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
    36
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
    37
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
    38
  """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
    39
  
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    40
  Args:
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    41
    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
    42
    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
    43
      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
    44
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    45
  Returns:
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    46
    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
    47
    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
    48
  """
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 272
diff changeset
    49
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 272
diff changeset
    50
  try:
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 272
diff changeset
    51
    access.checkIsDeveloper(request)
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 272
diff changeset
    52
  except  soc.logic.out_of_band.AccessViolationResponse, alt_response:
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 272
diff changeset
    53
    return alt_response.response()
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 272
diff changeset
    54
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
    55
  # create default template context for use with any templates
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 268
diff changeset
    56
  context = helper.responses.getUniversalContext(request)
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
    57
268
af1d7f48b361 Move helpers/list.py to helper/lists.py to avoid conflict with built-in type
Todd Larsen <tlarsen@google.com>
parents: 266
diff changeset
    58
  offset, limit = helper.lists.cleanListParameters(
265
3c2994f3b85f List views should have a selectable pagination "page" length:
Todd Larsen <tlarsen@google.com>
parents: 263
diff changeset
    59
      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
    60
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 233
diff changeset
    61
  # 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
    62
  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
    63
268
af1d7f48b361 Move helpers/list.py to helper/lists.py to avoid conflict with built-in type
Todd Larsen <tlarsen@google.com>
parents: 266
diff changeset
    64
  context['pagination_form'] = helper.lists.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
    65
  
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_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
    67
                    '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
    68
                    '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
    69
                    '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
    70
                      
268
af1d7f48b361 Move helpers/list.py to helper/lists.py to avoid conflict with built-in type
Todd Larsen <tlarsen@google.com>
parents: 266
diff changeset
    71
  context = helper.lists.setList(
232
7741d6b7ce7c Fix some style guide issues: keyword arguments are supposed to always be
Todd Larsen <tlarsen@google.com>
parents: 186
diff changeset
    72
      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
    73
      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
    74
272
00cea07656c0 Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents: 268
diff changeset
    75
  return helper.responses.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
    76