Back to index

moin  1.9.0~rc2
Classes | Functions
MoinMoin.util.web Namespace Reference

Classes

class  Color

Functions

def getIntegerInput
def makeSelection
def makeMultiSelection

Function Documentation

def MoinMoin.util.web.getIntegerInput (   request,
  fieldname,
  default = None,
  minval = None,
  maxval = None 
)
Get an integer value from a request parameter. If the value
    is out of bounds, it's made to fit into those bounds.

    Returns `default` in case of errors (not a valid integer, or field
    is missing).

Definition at line 9 of file web.py.

00009 
00010 def getIntegerInput(request, fieldname, default=None, minval=None, maxval=None):
00011     """ Get an integer value from a request parameter. If the value
00012         is out of bounds, it's made to fit into those bounds.
00013 
00014         Returns `default` in case of errors (not a valid integer, or field
00015         is missing).
00016     """
00017     try:
00018         result = int(request.values[fieldname])
00019     except (KeyError, ValueError):
00020         return default
00021     else:
00022         if minval is not None:
00023             result = max(result, minval)
00024         if maxval is not None:
00025             result = min(result, maxval)
00026         return result
00027 

def MoinMoin.util.web.makeMultiSelection (   name,
  values,
  selectedvals = None,
  size = 5,
  enabled = True 
)
Make a HTML multiple <select> element with named `name` from a value list.

The list can either be a list of strings, or a list of (value, label) tuples.
`selectedvals` is a list of values that should be pre-selected.

Definition at line 47 of file web.py.

00047 
00048 def makeMultiSelection(name, values, selectedvals=None, size=5, enabled=True):
00049     """Make a HTML multiple <select> element with named `name` from a value list.
00050 
00051     The list can either be a list of strings, or a list of (value, label) tuples.
00052     `selectedvals` is a list of values that should be pre-selected.
00053 
00054     """
00055     from MoinMoin.widget import html
00056     result = html.SELECT(name=name, size="%d" % int(size), multiple=True, disabled=not enabled)
00057     for val in values:
00058         if not isinstance(val, type(())):
00059             val = (val, val)
00060         result.append(html.OPTION(
00061             value=val[0], selected=(val[0] in selectedvals))
00062             .append(html.Text(val[1]))
00063         )
00064 
00065     return result

def MoinMoin.util.web.makeSelection (   name,
  values,
  selectedval = None,
  size = 1,
  multiple = False,
  enabled = True 
)
Make a HTML <select> element named `name` from a value list.
    The list can either be a list of strings, or a list of
    (value, label) tuples.

    `selectedval` is the value that should be pre-selected.

Definition at line 28 of file web.py.

00028 
00029 def makeSelection(name, values, selectedval=None, size=1, multiple=False, enabled=True):
00030     """ Make a HTML <select> element named `name` from a value list.
00031         The list can either be a list of strings, or a list of
00032         (value, label) tuples.
00033 
00034         `selectedval` is the value that should be pre-selected.
00035     """
00036     from MoinMoin.widget import html
00037     result = html.SELECT(name=name, size="%d" % int(size), multiple=multiple, disabled=not enabled)
00038     for val in values:
00039         if not isinstance(val, type(())):
00040             val = (val, val)
00041         result.append(html.OPTION(
00042             value=val[0], selected=(val[0] == selectedval))
00043             .append(html.Text(val[1]))
00044         )
00045 
00046     return result

Here is the caller graph for this function: