Skip to content

Commit 115eccc

Browse files
author
Richard Jones
committed
more doc, bugfix in Batch
1 parent c5b111e commit 115eccc

File tree

2 files changed

+118
-11
lines changed

2 files changed

+118
-11
lines changed

doc/customizing.txt

Lines changed: 105 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Customising Roundup
33
===================
44

5-
:Version: $Revision: 1.29 $
5+
:Version: $Revision: 1.30 $
66

77
.. This document borrows from the ZopeBook section on ZPT. The original is at:
88
http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
@@ -948,17 +948,23 @@ Method Description
948948
=========== =============================================================
949949
plain render a "plain" representation of the property
950950
field render a form edit field for the property
951-
stext specific to String properties - render the value of the
951+
stext only on String properties - render the value of the
952952
property as StructuredText (requires the StructureText module
953953
to be installed separately)
954-
multiline specific to String properties - render a multiline form edit
954+
multiline only on String properties - render a multiline form edit
955955
field for the property
956-
email specific to String properties - render the value of the
956+
email only on String properties - render the value of the
957957
property as an obscured email address
958+
reldate only on Date properties - render the interval between the
959+
date and now
960+
pretty only on Interval properties - render the interval in a
961+
pretty format (eg. "yesterday")
962+
menu only on Link and Multilink properties - render a form select
963+
list for this property
964+
reverse only on Multilink properties - produce a list of the linked
965+
items in reverse order
958966
=========== =============================================================
959967

960-
XXX do the other properties
961-
962968
The request variable
963969
~~~~~~~~~~~~~~~~~~~~
964970

@@ -996,6 +1002,22 @@ filterspec values to filter the index on
9961002
search_text text to perform a full-text search on for an index
9971003
=========== ================================================================
9981004

1005+
There are several methods available on the request variable:
1006+
1007+
=============== ============================================================
1008+
Method Description
1009+
=============== ============================================================
1010+
description render a description of the request - handle for the page
1011+
title
1012+
indexargs_form render the current index args as form elements
1013+
indexargs_url render the current index args as a URL
1014+
base_javascript render some javascript that is used by other components of
1015+
the templating
1016+
batch run the current index args through a filter and return a
1017+
list of items (see `hyperdb item wrapper`_, and
1018+
`batching`_)
1019+
=============== ============================================================
1020+
9991021
The db variable
10001022
~~~~~~~~~~~~~~~
10011023

@@ -1010,6 +1032,83 @@ want access to the "user" class, for example, you would use::
10101032
The access results in a `hyperdb class wrapper`_.
10111033

10121034

1035+
The util variable
1036+
~~~~~~~~~~~~~~~~~
1037+
1038+
Note: this is implemented by the roundup.cgi.templating.TemplatingUtils class.
1039+
1040+
=============== ============================================================
1041+
Method Description
1042+
=============== ============================================================
1043+
Batch return a batch object using the supplied list
1044+
=============== ============================================================
1045+
1046+
Batching
1047+
::::::::
1048+
1049+
Use Batch to turn a list of items, or item ids of a given class, into a series
1050+
of batches. Its usage is::
1051+
1052+
python:util.Batch(sequence, size, start, end=0, orphan=0, overlap=0)
1053+
1054+
or, to get the current index batch::
1055+
1056+
request/batch
1057+
1058+
The parameters are:
1059+
1060+
========= ==================================================================
1061+
Parameter Usage
1062+
========= ==================================================================
1063+
sequence a list of HTMLItems
1064+
size how big to make the sequence.
1065+
start where to start (0-indexed) in the sequence.
1066+
end where to end (0-indexed) in the sequence.
1067+
orphan if the next batch would contain less items than this
1068+
value, then it is combined with this batch
1069+
overlap the number of items shared between adjacent batches
1070+
========= ==================================================================
1071+
1072+
All of the parameters are assigned as attributes on the batch object. In
1073+
addition, it has several more attributes:
1074+
1075+
=============== ============================================================
1076+
Attribute Description
1077+
=============== ============================================================
1078+
start indicates the start index of the batch. *Note: unlike the
1079+
argument, is a 1-based index (I know, lame)*
1080+
first indicates the start index of the batch *as a 0-based
1081+
index*
1082+
length the actual number of elements in the batch
1083+
sequence_length the length of the original, unbatched, sequence.
1084+
=============== ============================================================
1085+
1086+
And several methods:
1087+
1088+
=============== ============================================================
1089+
Method Description
1090+
=============== ============================================================
1091+
previous returns a new Batch with the previous batch settings
1092+
next returns a new Batch with the next batch settings
1093+
propchanged detect if the named property changed on the current item
1094+
when compared to the last item
1095+
=============== ============================================================
1096+
1097+
An example of batching::
1098+
1099+
<table class="otherinfo">
1100+
<tr><th colspan="4" class="header">Existing Keywords</th></tr>
1101+
<tr tal:define="keywords db/keyword/list"
1102+
tal:repeat="start python:range(0, len(keywords), 4)">
1103+
<td tal:define="batch python:utils.Batch(keywords, 4, start)"
1104+
tal:repeat="keyword batch" tal:content="keyword/name">keyword here</td>
1105+
</tr>
1106+
<tr><td colspan="4" style="border-top: 1px solid gray">&nbsp;</td></tr>
1107+
</table>
1108+
1109+
... which will produce a table with four columns containing the items of the
1110+
"keyword" class (well, their "name" anyway).
1111+
10131112
Displaying Properties
10141113
---------------------
10151114

roundup/cgi/templating.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,10 @@ def field(self, size = 30):
782782
return '<input name="%s" value="%s" size="%s">'%(self._name, value, size)
783783

784784
def reldate(self, pretty=1):
785+
''' Render the interval between the date and now.
786+
787+
If the "pretty" flag is true, then make the display pretty.
788+
'''
785789
if not self._value:
786790
return ''
787791

@@ -800,6 +804,8 @@ def plain(self):
800804
return str(self._value)
801805

802806
def pretty(self):
807+
''' Render the interval in a pretty format (eg. "yesterday")
808+
'''
803809
return self._value.pretty()
804810

805811
def field(self, size = 30):
@@ -881,6 +887,8 @@ def field(self):
881887

882888
def menu(self, size=None, height=None, showid=0, additional=[],
883889
**conditions):
890+
''' Render a form select list for this property
891+
'''
884892
value = self._value
885893

886894
# sort function
@@ -994,6 +1002,8 @@ def field(self, size=30, showid=0):
9941002

9951003
def menu(self, size=None, height=None, showid=0, additional=[],
9961004
**conditions):
1005+
''' Render a form select list for this property
1006+
'''
9971007
value = self._value
9981008

9991009
# sort function
@@ -1276,7 +1286,7 @@ def indexargs_form(self, columns=1, sort=1, group=1, filter=1,
12761286
l.append(s%(':startwith', self.startwith))
12771287
return '\n'.join(l)
12781288

1279-
def indexargs_href(self, url, args):
1289+
def indexargs_url(self, url, args):
12801290
''' embed the current index args in a URL '''
12811291
l = ['%s=%s'%(k,v) for k,v in args.items()]
12821292
if self.columns and not args.has_key(':columns'):
@@ -1305,6 +1315,7 @@ def indexargs_href(self, url, args):
13051315
if not args.has_key(':startwith'):
13061316
l.append(':startwith=%s'%self.startwith)
13071317
return '%s?%s'%(url, '&'.join(l))
1318+
indexargs_href = indexargs_url
13081319

13091320
def base_javascript(self):
13101321
return '''
@@ -1381,6 +1392,7 @@ def __init__(self, client, sequence, size, start, end=0, orphan=0,
13811392
self.client = client
13821393
self.last_index = self.last_item = None
13831394
self.current_item = None
1395+
self.sequence_length = len(sequence)
13841396
ZTUtils.Batch.__init__(self, sequence, size, start, end, orphan,
13851397
overlap)
13861398

@@ -1427,10 +1439,6 @@ def next(self):
14271439
return Batch(self.client, self._sequence, self._size,
14281440
self.end - self.overlap, 0, self.orphan, self.overlap)
14291441

1430-
def length(self):
1431-
self.sequence_length = l = len(self._sequence)
1432-
return l
1433-
14341442
class TemplatingUtils:
14351443
''' Utilities for templating
14361444
'''

0 commit comments

Comments
 (0)