app/soc/views/site/docs/list.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Wed, 01 Oct 2008 22:19:22 +0000
changeset 259 74eb6b01c82c
parent 234 a019afb4b80f
child 263 9b39d93b677f
permissions -rw-r--r--
Add basic Sponsors List, Create New Sponsor, Sponsor Public Profile views. Change all properties in Group model as required for now. Remaining TODO: write validation functions for Sponsor edit and create form fields that need additional validation (like address, phone number format). Patch by: Pawel Solyga Review 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
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
from soc.logic import document
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)
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    59
  
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
  docs = document.getWorksForOffsetAndLimit(
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    61
      offset=offset, limit=limit, cls=soc.models.document.Document)
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    62
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    63
  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
    64
                    'list_pagination': 'soc/list/list_pagination.html',
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    65
                    '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
    66
                    '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
    67
                      
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    68
  context = list_helpers.setList(
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    69
      request, context, docs, 
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    70
      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
    71
a019afb4b80f Implement a Developer list view of all Documents.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    72
  return response_helpers.respond(request, template, context)