app/soc/views/site/docs/list.py
author Todd Larsen <tlarsen@google.com>
Fri, 03 Oct 2008 01:32:34 +0000
changeset 263 9b39d93b677f
parent 234 a019afb4b80f
child 265 3c2994f3b85f
permissions -rw-r--r--
Make findNearestUsers() code in soc/logic/site/id_user.py more generic and move it to soc/logic/model.py. Orginal findNearest...() functions in id_user.py are now convenience wrappers. Add typed-query string construction functions to model.py. Move getFulLClassName() from key_name.py model.py, since it has more to do with Model types than key names. Swap 'offset' and 'limit' and make 'limit' arguments non-optional. Also, stop adding 1 inside the ...ForLimitAndOffset() functions and make the callers do it (since it was being added for a very UI-specific reason of whether or not to display a "Next>" link). Patch by: Todd Larsen Review by: Pawel Solyga Review URL: http://codereviews.googleopensourceprograms.com/1401
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
234
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""Developer views for listing Documents.
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
"""
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
__authors__ = [
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
  '"Todd Larsen" <tlarsen@google.com>',
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    22
  ]
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
263
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 234
diff changeset
    25
from soc.logic import works
234
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
from soc.views import simple
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    27
from soc.views.helpers import list_helpers
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
from soc.views.helpers import response_helpers
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    29
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
import soc.models.document
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    31
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    32
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    33
DEF_SITE_DOCS_LIST_ALL_TMPL = 'soc/site/docs/list/all.html'
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    34
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    35
def all(request, template=DEF_SITE_DOCS_LIST_ALL_TMPL):
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    36
  """Show a list of all Documents (limit rows per page).
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    37
  
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    38
  Args:
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    39
    request: the standard Django HTTP request object
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
    template: the "sibling" template (or a search list of such templates)
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    41
      from which to construct an alternate template name (or names)
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    43
  Returns:
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    44
    A subclass of django.http.HttpResponse which either contains the form to
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
    be filled out, or a redirect to the correct view in the interface.
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46
  """
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    47
  # create default template context for use with any templates
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    48
  context = response_helpers.getUniversalContext(request)
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    49
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    50
  alt_response = simple.getAltResponseIfNotDeveloper(request,
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    51
                                                     context=context)
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
  if alt_response:
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
    return alt_response  
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    54
  
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    55
  offset = request.GET.get('offset')
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    56
  limit = request.GET.get('limit')
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    57
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    58
  offset, limit = list_helpers.getListParemeters(offset=offset, limit=limit)
263
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 234
diff changeset
    59
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 234
diff changeset
    60
  # 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: 234
diff changeset
    61
  docs = works.getWorksForLimitAndOffset(
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 234
diff changeset
    62
      limit + 1, offset=offset, cls=soc.models.document.Document)
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 234
diff changeset
    63
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 234
diff changeset
    64
  # TODO(tlarsen): uncomment when pagination select control is working.
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 234
diff changeset
    65
  # form = list_helpers.makeSelectNumItemsForm(request, limit)
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 234
diff changeset
    66
  # context['form'] = form
234
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    67
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    68
  list_templates = {'list_main': 'soc/list/list_main.html',
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    69
                    'list_pagination': 'soc/list/list_pagination.html',
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    70
                    'list_row': 'soc/site/docs/list/docs_row.html',
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    71
                    'list_heading': 'soc/site/docs/list/docs_heading.html'}
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    72
                      
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    73
  context = list_helpers.setList(
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    74
      request, context, docs, 
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    75
      offset=offset, limit=limit, list_templates=list_templates)
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    76
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    77
  return response_helpers.respond(request, template, context)