app/soc/views/helpers/list_helpers.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Mon, 22 Sep 2008 14:08:37 +0000
changeset 185 2f3bd84bb106
child 228 2204287da374
permissions -rw-r--r--
Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc). Add list default templates and CSS classes. Patch by: Pawel Solyga Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
185
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     2
#
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     4
#
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     8
#
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    10
#
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    16
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    17
"""Helpers used to render lists.
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    18
"""
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    19
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    20
__authors__ = [
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    21
  '"Pawel Solyga" <pawel.solyga@gmail.com>',
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    22
  ]
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    23
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    24
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    25
DEF_LIMIT = 10
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    26
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    27
def getListParemeters(offset=None, limit=None):
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    28
  """Updates and validates offset and limit values of the list.
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    29
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    30
  Args:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    31
    offset: offset in list which defines first item to return
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    32
    limit: max amount of items per page
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    33
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    34
  Returns:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    35
    updated offset and limit values
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    36
  """
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    37
  # update offset value 
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    38
  if offset:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    39
    try:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    40
      offset = int(offset)
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    41
    except:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    42
      offset = 0
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    43
    else:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    44
      offset = max(0, offset)
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    45
  else:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    46
    offset = 0
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    47
  
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    48
  # update limit value
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    49
  if limit:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    50
    try:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    51
      limit = int(limit)
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    52
    except:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    53
      limit = DEF_LIMIT
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    54
    else:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    55
      limit = max(1, min(limit, 100))
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    56
  else:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    57
    limit = DEF_LIMIT
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    58
  
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    59
  return offset, limit
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    60
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    61
DEF_LIST_TEMPLATES = {'list_main': 'soc/list/list_main.html',
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    62
                      'list_pagination': 'soc/list/list_pagination.html',
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    63
                      'list_row': 'soc/list/list_row.html',
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    64
                      'list_heading': 'soc/list/list_heading.html'}
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    65
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    66
def setList(request, context, list_data,
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    67
            offset=0, limit=0, list_templates=DEF_LIST_TEMPLATES):
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    68
  """Updates template context dict with variables used for rendering lists.
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    69
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    70
  Args:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    71
    request: the Django HTTP request object
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    72
    context: the template context dict to be updated in-place (pass in a copy
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    73
      if the original must not be modified), or None if a new one is to be
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    74
      created; any existing fields already present in the context dict passed
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    75
      in by the caller are left unaltered 
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    76
    list_data: array of data to be displayed in the list
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    77
    offset: offset in list which defines first item to return
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    78
    limit: max amount of items per page
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    79
    list_templates: templates that are used when rendering list
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    80
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    81
  Returns:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    82
    updated template context dict supplied by the caller or a new context
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    83
    dict if the caller supplied None
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    84
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    85
    {
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    86
      'list_data': list data to be displayed 
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    87
      'list_main': url to list main template
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    88
      'list_pagination': url to list pagination template
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    89
      'list_row': url to list row template
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    90
      'list_heading': url to list heading template
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    91
      'limit': max amount of items per page,
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    92
      'newest': url to first page of the list 
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    93
      'prev': url to previous page 
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    94
      'next': url to next page
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    95
      'first': offset of the first item in the list
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    96
      'last': offest of the lst item in the list
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    97
    }
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    98
  """  
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    99
  if not list_data:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   100
    list_data = []
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   101
  
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   102
  more = bool(list_data[limit:])
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   103
  if more:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   104
    del list_data[limit:]
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   105
  if more:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   106
    next = request.path + '?offset=%d&limit=%d' % (offset+limit, limit)
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   107
  else:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   108
    next = ''
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   109
  if offset > 0:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   110
    prev = request.path + '?offset=%d&limit=%d' % (max(0, offset-limit), limit)
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   111
  else:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   112
    prev = ''
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   113
  newest = ''
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   114
  if offset > limit:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   115
    newest = request.path + '?limit=%d' % limit
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   116
  
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   117
  if not context:
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   118
    context = {}
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   119
  
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   120
  context.update(
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   121
    {'list_data': list_data, 
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   122
     'list_main': list_templates['list_main'],
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   123
     'list_pagination': list_templates['list_pagination'],
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   124
     'list_row': list_templates['list_row'],
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   125
     'list_heading': list_templates['list_heading'],
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   126
     'limit': limit,
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   127
     'newest': newest, 
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   128
     'prev': prev, 
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   129
     'next': next,
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   130
     'first': offset+1,
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   131
     'last': len(list_data) > 1 and offset+len(list_data) or None})
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   132
  
2f3bd84bb106 Add list_helpers functions that are going to be used when rendering list views like (Users List, Sponsors List etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   133
  return context