app/soc/views/helpers/template_helpers.py
author Todd Larsen <tlarsen@google.com>
Fri, 19 Sep 2008 04:50:42 +0000
changeset 168 87296bdfc9c6
parent 141 e120c24b89e2
child 183 37d98c3cefa5
permissions -rw-r--r--
Added getSingleIndexedParamValue() that retrieves an index into a list of values from the named query parameter, and then indexes into the supplied list of values to return the corresponding value from the list. Used to convert numeric index query parameters passed by POST to the GET redirect target, so that the GET code can display messages, etc. (without passing the message itself as a query argument and having to escape it or have silly people pass in their own...).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
113
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""Helpers for manipulating templates.
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
"""
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
__authors__ = [
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
  '"Todd Larsen" <tlarsen@google.com>',
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 125
diff changeset
    22
  '"Pawel Solyga" <pawel.solyga@gmail.com>'
113
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
  ]
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
125
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    26
def makeSiblingTemplatesList(templates, new_template_file,
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    27
                             default_template=None):
113
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
  """Converts template paths into a list of "sibling" templates.
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    29
  
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
  Args:
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    31
    templates: search list of templates (or just a single template not in a
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    32
      list) from which template paths will be extracted (discarding the final
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    33
      template file name of each template)
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    34
    new_template_file: new "sibling" template file to append to each extracted
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    35
      template path
125
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    36
    default_template: a default template (or a list of them) to append to the
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    37
      end of the generated "sibling" template paths; default is None
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    38
 
113
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    39
  Returns:
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
    A list of potential "sibling" templates named by new_template_file located
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    41
    in the paths of the templates in the supplied list.  For example, from:
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
      ['foo/bar/the_old_template.html', 'foo/the_old_template.html']
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    43
    to:
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    44
      ['foo/bar/some_new_template.html', 'foo/some_new_template.html']
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
  """
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46
  if not isinstance(templates, (list, tuple)):
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    47
    templates = [templates]
26d86de67714 Helpers for manipulating templates and template search paths.
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    48
125
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    49
  if default_template is None:
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    50
    default_template = []
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    51
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    52
  if not isinstance(default_template, (list, tuple)):
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    53
    default_template = [default_template]
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    54
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    55
  sibling_templates = [
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    56
    '%s/%s' % (t.rsplit('/', 1)[0], new_template_file) for t in templates]
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    57
155f43a0fa68 An emerging pattern with makeSiblingTemplatesList() is that views calling that
Todd Larsen <tlarsen@google.com>
parents: 113
diff changeset
    58
  return sibling_templates + default_template
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 125
diff changeset
    59
168
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    60
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 125
diff changeset
    61
def unescape(html): 
168
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    62
  """Returns the given HTML with ampersands, quotes and carets decoded.
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    63
  """ 
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 125
diff changeset
    64
  if not isinstance(html, basestring): 
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 125
diff changeset
    65
    html = str(html) 
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 125
diff changeset
    66
  
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 125
diff changeset
    67
  html.replace('&amp;', '&').replace('&lt;', '<')
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 125
diff changeset
    68
  html.replace('&gt;', '>').replace('&quot;', '"').replace('&#39;',"'")
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 125
diff changeset
    69
  return html
168
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    70
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    71
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    72
def getSingleIndexedParamValue(request, param_name, values=()):
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    73
  """Returns a value indexed by a query parameter in the HTTP request.
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    74
  
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    75
  Args:
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    76
    request: the Django HTTP request object
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    77
    param_name: name of the query parameter in the HTTP request
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    78
    values: list (or tuple) of ordered values; one of which is
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    79
      retrieved by the index value of the param_name argument in
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    80
      the HTTP request
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    81
      
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    82
  Returns:
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    83
    None if the query parameter was not present, was not an integer, or
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    84
      was an integer that is not a valid [0..len(values)-1] index into
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    85
      the values list.
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    86
    Otherwise, returns values[int(param_name value)]
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    87
  """
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    88
  value_idx = request.GET.get(param_name)
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    89
  
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    90
  if isinstance(value_idx, (tuple, list)):
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    91
    # keep only the first argument if multiple are present
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    92
    value_idx = value_idx[0]
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    93
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    94
  try:
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    95
    # GET parameter 'param_name' should be an integer value index
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    96
    value_idx = int(value_idx)
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    97
  except:
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    98
    # ignore bogus or missing parameter values, so return None (no message)
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
    99
    return None
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   100
    
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   101
  if value_idx < 0:
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   102
    # value index out of range, so return None (no value)
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   103
    return None
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   104
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   105
  if value_idx >= len(values):
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   106
    # value index out of range, so return None (no value)
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   107
    return None
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   108
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   109
  # return value associated with valid value index
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   110
  return values[value_idx]
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   111
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   112
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   113
def getSingleIndexedParamValueIfMissing(value, request, param_name,
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   114
                                        values=()):
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   115
  """Returns missing value indexed by a query parameter in the HTTP request.
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   116
  
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   117
  Args:
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   118
    value: an existing value, or a "False" value such as None
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   119
    request, param_name, values: see getSingleIndexParamValue()
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   120
    
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   121
  Returns:
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   122
    value, if value is "non-False"
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   123
    Otherwise, returns getSingleIndexedParamValue() result.
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   124
  """
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   125
  if value:
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   126
    # value already present, so return it
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   127
    return value
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   128
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   129
  return getSingleIndexedParamValue(request, param_name, values=values)
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   130
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   131
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   132
# TODO(tlarsen):  write getMultipleIndexParamValues() that returns a
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   133
#   list of values if present, omitting those values that are
87296bdfc9c6 Added getSingleIndexedParamValue() that retrieves an index into a list of
Todd Larsen <tlarsen@google.com>
parents: 141
diff changeset
   134
#   out of range