app/soc/views/site/user/list.py
author Todd Larsen <tlarsen@google.com>
Sat, 15 Nov 2008 03:12:33 +0000
changeset 481 94834a1e6c01
parent 445 31927f21970d
child 482 839740b061ad
permissions -rw-r--r--
Attempt to rename User.id to User.account, in preparation for making User be derived from Linkable, which will have a property named 'id'. Patch by: Todd Larsen
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
309
7190b224c701 Made the existing code use the new soc.logic.models
Sverre Rabbelier <srabbelier@gmail.com>
parents: 303
diff changeset
    25
from soc.logic import models
316
9efdc7bc3565 Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 309
diff changeset
    26
from soc.views import helper
303
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents: 299
diff changeset
    27
from soc.views.helper import access
365
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 358
diff changeset
    28
from soc.views.helper import decorators
316
9efdc7bc3565 Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 309
diff changeset
    29
9efdc7bc3565 Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 309
diff changeset
    30
import soc.logic
9efdc7bc3565 Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 309
diff changeset
    31
import soc.models.user
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
    32
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
    33
import soc.views.helper.responses
303
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents: 299
diff changeset
    34
import soc.views.out_of_band
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
263
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 233
diff changeset
    36
445
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 374
diff changeset
    37
DEF_SITE_USER_LIST_ALL_TMPL = 'soc/models/list.html'
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
    38
365
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 358
diff changeset
    39
@decorators.view
358
843d83b87282 Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 316
diff changeset
    40
def all(request, page=None, template=DEF_SITE_USER_LIST_ALL_TMPL):
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
    41
  """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
    42
  
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    43
  Args:
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    44
    request: the standard Django HTTP request object
358
843d83b87282 Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 316
diff changeset
    45
    page: a soc.logic.site.page.Page object which is abstraction that combines 
843d83b87282 Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 316
diff changeset
    46
      a Django view with sidebar menu info
233
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    47
    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
    48
      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
    49
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    50
  Returns:
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    51
    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
    52
    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
    53
  """
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 272
diff changeset
    54
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 272
diff changeset
    55
  try:
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 272
diff changeset
    56
    access.checkIsDeveloper(request)
303
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents: 299
diff changeset
    57
  except  soc.views.out_of_band.AccessViolationResponse, alt_response:
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 272
diff changeset
    58
    return alt_response.response()
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 272
diff changeset
    59
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
    60
  # 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
    61
  context = helper.responses.getUniversalContext(request)
374
9363b9dc2983 Add the Page object to the context of each view. Update templates to make
Todd Larsen <tlarsen@google.com>
parents: 365
diff changeset
    62
  context['page'] = page
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
    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
  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
    65
      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
    66
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 233
diff changeset
    67
  # Fetch one more to see if there should be a 'next' link
309
7190b224c701 Made the existing code use the new soc.logic.models
Sverre Rabbelier <srabbelier@gmail.com>
parents: 303
diff changeset
    68
  users = models.user.logic.getForLimitAndOffset(limit + 1, offset=offset)
263
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 233
diff changeset
    69
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
    70
  context['pagination_form'] = helper.lists.makePaginationForm(request, limit)
374
9363b9dc2983 Add the Page object to the context of each view. Update templates to make
Todd Larsen <tlarsen@google.com>
parents: 365
diff changeset
    71
445
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 374
diff changeset
    72
  list_templates = {
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 374
diff changeset
    73
      'list_main': 'soc/list/list_main.html',
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 374
diff changeset
    74
      'list_pagination': 'soc/list/list_pagination.html',
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 374
diff changeset
    75
      'list_row': 'soc/user/list/user_row.html',
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 374
diff changeset
    76
      'list_heading': 'soc/user/list/user_heading.html'
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 374
diff changeset
    77
      }
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 374
diff changeset
    78
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
    79
  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
    80
      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
    81
      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
    82
365
74dec172944e Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 358
diff changeset
    83
  return helper.responses.respond(request, template, context)