app/soc/views/site/user/list.py
author Todd Larsen <tlarsen@google.com>
Thu, 02 Oct 2008 20:22:15 +0000
changeset 262 52a42831d9d6
parent 233 42733f531ebf
child 263 9b39d93b677f
permissions -rw-r--r--
Factor out an isIdAvailable() function from EditForm.clean_id() in soc/views/site/user/profile.py and add it to soc/logic/site/id_user.py. Addresses some comments on r614. Patch by: Todd Larsen Review by: Pawel Solyga Review URL: http://codereviews.googleopensourceprograms.com/1202
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
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
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
    33
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
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
    35
  """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
    36
  
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    37
  Args:
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    38
    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
    39
    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
    40
      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
    41
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    42
  Returns:
42733f531ebf Add missing all() __doc__ string comments: "Args:" and "Returns:" sections.
Todd Larsen <tlarsen@google.com>
parents: 232
diff changeset
    43
    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
    44
    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
    45
  """
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
  # 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
    47
  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
    48
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
  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
    50
                                                     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
    51
  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
    52
    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
    53
  
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
  offset = request.GET.get('offset')
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
  limit = request.GET.get('limit')
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
    56
232
7741d6b7ce7c Fix some style guide issues: keyword arguments are supposed to always be
Todd Larsen <tlarsen@google.com>
parents: 186
diff changeset
    57
  offset, limit = list_helpers.getListParemeters(offset=offset, limit=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
    58
  
232
7741d6b7ce7c Fix some style guide issues: keyword arguments are supposed to always be
Todd Larsen <tlarsen@google.com>
parents: 186
diff changeset
    59
  users = id_user.getUsersForOffsetAndLimit(offset=offset, limit=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
    60
  
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
    61
  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
    62
                    '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
    63
                    '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
    64
                    '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
    65
                      
232
7741d6b7ce7c Fix some style guide issues: keyword arguments are supposed to always be
Todd Larsen <tlarsen@google.com>
parents: 186
diff changeset
    66
  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
    67
      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
    68
      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
    69
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
  return response_helpers.respond(request, template, 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
    71