app/soc/views/site/docs/list.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sun, 12 Oct 2008 00:12:53 +0000
changeset 299 a1cc853a56e5
parent 294 1fdaab4a6ef2
child 303 4f1bb54ddae5
permissions -rw-r--r--
Refactor nearly all the soc.logic code to use the Base class Instead of having a lot of duplicate code, this patch aims to reduce this duplication by introducing a Base abstraction. Patch by: Sverre Rabbelier Reviewed by: to-be-reviewed
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
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 294
diff changeset
    25
import soc.logic
294
1fdaab4a6ef2 Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 272
diff changeset
    26
from soc.logic.helper import access
234
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.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
234
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
import soc.models.document
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    33
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_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
    36
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    37
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
    38
  """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
    39
  
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
  Args:
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    41
    request: the standard Django HTTP request object
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
    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
    43
      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
    44
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
  Returns:
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46
    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
    47
    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
    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
234
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.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)
234
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.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: 234
diff changeset
    60
9b39d93b677f Make findNearestUsers() code in soc/logic/site/id_user.py more generic and
Todd Larsen <tlarsen@google.com>
parents: 234
diff changeset
    61
  # Fetch one more to see if there should be a 'next' link
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 294
diff changeset
    62
  docs = soc.logic.work_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: 234
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)
234
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    65
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    66
  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
    67
                    'list_pagination': 'soc/list/list_pagination.html',
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    68
                    '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
    69
                    '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
    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(
234
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    72
      request, context, docs, 
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    73
      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
    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)