Commit ca900882 authored by Amos Latteier's avatar Amos Latteier

Converted math, random, string, and sequence module documentation to API help,...

Converted math, random, string, and sequence module documentation to API help, from dtml help. This change reflects the fact that you can use these modules from Python-based scripts and page templates as well as from DTML.
parent 893eda71
......@@ -207,13 +207,13 @@ functions: DTML Functions
See Also
"'string' module":dtml-string.stx
"'string' module":string.py
"'random' module":dtml-random.stx
"'random' module":random.py
"'math' module":dtml-math.stx
"'math' module":math.py
"'sequence' module":dtml-sequence.stx
"'sequence' module":sequence.py
"Built-in Python Functions":http://www.python.org/doc/current/lib/built-in-funcs.html
......
sequence: DTML Sequence Functions
The 'sequence' module provides a sequence sorting function.
Functions
sort(seq,(sort)) -- Sort the sequence *seq* of objects by the
optional sort schema *sort*. *sort* is a sequence of tuples
'(key, func, direction)' that describe the sort order.
- key -- Attribute of the object to be sorted.
- func -- Defines the compare function (optional). Allowed values:
- "cmp" -- Standard Python comparison function
- "nocase" -- Case-insensitive comparison
- "strcoll" or "locale" -- Locale-aware string comparison
- "strcoll_nocase" or "locale_nocase" -- Locale-aware
case-insensitive string comparison
- other -- A specified, user-defined comparison function,
should return 1, 0, -1.
- direction -- defines the sort direction for the key (optional).
(allowed values: "asc", "desc")
Examples
Sort child object (using the 'objectValues' method) by id (using
the 'getId' method), ignoring case::
<dtml-in expr="_.sequence.sort(objectValues(),
(('getId', 'nocase'),))">
<dtml-var getId> <br>
</dtml-in>
Sort child objects by title (ignoring case) and date (from newest
to oldest)::
<dtml-in expr="_.sequence.sort(objectValues(),
(('title', 'nocase'),
('bobobase_modification_time',
'cmp', 'desc')
))">
<dtml-var title> <dtml-var bobobase_modification_time> <br>
</dtml-in>
See Also
"Python cmp function":http://www.python.org/doc/lib/built-in-funcs.html
math: DTML Math Functions
"""
math: Python 'math' module
The 'math' module provides trigonometric and other math
functions. It is a standard Python module.
......@@ -11,7 +12,7 @@ math: DTML Math Functions
"Python 'math'
module":http://www.python.org/doc/current/lib/module-math.html
documentation at Python.org
"""
......
random: DTML Pseudo-Random Number Functions
"""
random: Python 'random' module
The 'random' module provides pseudo-random number functions. With
it, you can generate random numbers and select random elements from
......@@ -12,6 +13,6 @@ random: DTML Pseudo-Random Number Functions
"Python 'random'
module":http://www.python.org/doc/current/lib/module-whrandom.html
documentation at Python.org
"""
"""
sequence: Sequence sorting module
This module provides a 'sort' function for use with DTML, Page
Templates, and Python-based Scripts.
"""
def sort(seq, sort):
"""
Sort the sequence *seq* of objects by the optional sort schema
*sort*. *sort* is a sequence of tuples '(key, func, direction)'
that describe the sort order.
key -- Attribute of the object to be sorted.
func -- Defines the compare function (optional). Allowed values:
"cmp" -- Standard Python comparison function
"nocase" -- Case-insensitive comparison
"strcoll" or "locale" -- Locale-aware string comparison
"strcoll_nocase" or "locale_nocase" -- Locale-aware
case-insensitive string comparison
other -- A specified, user-defined comparison function, should
return 1, 0, -1.
direction -- defines the sort direction for the key (optional).
(allowed values: "asc", "desc")
DTML Examples
Sort child object (using the 'objectValues' method) by id (using
the 'getId' method), ignoring case::
<dtml-in expr="_.sequence.sort(objectValues(),
(('getId', 'nocase'),))">
<dtml-var getId> <br>
</dtml-in>
Sort child objects by title (ignoring case) and date (from newest
to oldest)::
<dtml-in expr="_.sequence.sort(objectValues(),
(('title', 'nocase'),
('bobobase_modification_time',
'cmp', 'desc')
))">
<dtml-var title> <dtml-var bobobase_modification_time> <br>
</dtml-in>
Page Template Examples
You can use the 'sequence.sort' function in Python expressions
to sort objects. Here's an example that mirrors the DTML example
above::
<table tal:define="objects here/objectValues;
sort_on python:(('title', 'nocase', 'asc'),
('bobobase_modification_time', 'cmp', 'desc'));
sorted_objects python:sequence.sort(objects, sort_on)">
<tr tal:repeat="item sorted_objects">
<td tal:content="item/title">title</td>
<td tal:content="item/bobobase_modification_time">
modification date</td>
</tr>
</table>
This example iterates over a sorted list of object, drawing a
table row for each object. The objects are sorted by title and
modification time.
See Also
"Python cmp function":http://www.python.org/doc/lib/built-in-funcs.html
"""
string: DTML String Functions
"""
string: Python 'string' module
The 'string' modules provides string manipulation, conversion, and
searching functions. It is a standard Python module.
The 'string' module provides string manipulation, conversion, and
searching functions. It is a standard Python module.
Since Zope 2.4 requires Python 2.1, make sure to consult the Python
2.1 documentation.
......@@ -11,7 +12,7 @@ string: DTML String Functions
"Python 'string'
module":http://www.python.org/doc/current/lib/module-string.html
documentation at Python.org
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment