Skip to content

Commit

Permalink
merged toby-dtml-in-namespace-branch for collector 358: new dtml-in p…
Browse files Browse the repository at this point in the history
…arameter no_push_item
  • Loading branch information
Toby Dickenson committed Apr 24, 2002
1 parent a236b48 commit 4bdf140
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
26 changes: 18 additions & 8 deletions DT_In.py
Expand Up @@ -76,8 +76,9 @@
need of reversing on the fly.
Within an 'in' block, variables are substituted from the
elements of the iteration. The elements may be either
instance or mapping objects. In addition, the variables:
elements of the iteration unless the 'no_push_item' optional
is specified. The elements may be either instance or mapping
objects. In addition, the variables:
'sequence-item' -- The element.
Expand Down Expand Up @@ -330,8 +331,8 @@
''' #'

__rcs_id__='$Id: DT_In.py,v 1.57 2001/11/28 15:50:54 matt Exp $'
__version__='$Revision: 1.57 $'[11:-2]
__rcs_id__='$Id: DT_In.py,v 1.58 2002/04/24 14:38:40 htrd Exp $'
__version__='$Revision: 1.58 $'[11:-2]

import sys
from DT_Util import ParseError, parse_params, name_param, str
Expand All @@ -355,7 +356,7 @@ def __call__(self, blocks):

class InClass:
elses=None
expr=sort=batch=mapping=None
expr=sort=batch=mapping=no_push_item=None
start_name_re=None
reverse=None
sort_expr=reverse_expr=None
Expand All @@ -364,6 +365,7 @@ def __init__(self, blocks):
tname, args, section = blocks[0]
args=parse_params(args, name='', start='1',end='-1',size='10',
orphan='0',overlap='1',mapping=1,
no_push_item=1,
skip_unauthorized=1,
previous=1, next=1, expr='', sort='',
reverse=1, sort_expr='', reverse_expr='',
Expand All @@ -384,6 +386,9 @@ def __init__(self, blocks):
if has_key('reverse'):
self.reverse=args['reverse']

if has_key('no_push_item'):
self.no_push_item=args['no_push_item']

if has_key('mapping'): self.mapping=args['mapping']
for n in 'start', 'size', 'end':
if has_key(n): self.batch=1
Expand Down Expand Up @@ -453,6 +458,7 @@ def renderwb(self, md):
params=self.args

mapping=self.mapping
no_push_item=self.no_push_item

if self.sort_expr is not None:
self.sort=self.sort_expr.eval(md)
Expand Down Expand Up @@ -584,7 +590,9 @@ def renderwb(self, md):
if t is TupleType and len(client)==2:
client=client[1]

if mapping:
if no_push_item:
pushed = 0
elif mapping:
pushed = 1
push(client)
elif t in StringTypes:
Expand Down Expand Up @@ -630,7 +638,7 @@ def renderwob(self, md):

section=self.section
mapping=self.mapping

no_push_item=self.no_push_item

if self.sort_expr is not None:
self.sort=self.sort_expr.eval(md)
Expand Down Expand Up @@ -683,7 +691,9 @@ def renderwob(self, md):
if t is TupleType and len(client)==2:
client=client[1]

if mapping:
if no_push_item:
pushed = 0
elif mapping:
pushed = 1
push(client)
elif t in StringTypes:
Expand Down
16 changes: 14 additions & 2 deletions tests/testDTML.py
Expand Up @@ -13,8 +13,8 @@
"""Document Template Tests
"""

__rcs_id__='$Id: testDTML.py,v 1.10 2002/02/06 19:13:36 chrisw Exp $'
__version__='$Revision: 1.10 $'[11:-2]
__rcs_id__='$Id: testDTML.py,v 1.11 2002/04/24 14:38:41 htrd Exp $'
__version__='$Revision: 1.11 $'[11:-2]

import sys, os
import unittest
Expand Down Expand Up @@ -382,6 +382,18 @@ def testRaise(self):
assert str(res) == 'success!', `res`


def testNoItemPush(self):
data=d(sec='B', name='XXX', sub=(d(name='b1'),d(name='b2',sec='XXX')))
html = """
<dtml-with data mapping><dtml-in sub no_push_item>
<dtml-var sec>.<dtml-with sequence-item mapping><dtml-var name></dtml-with>
</dtml-in></dtml-with>
"""
expected = """
B.b1 B.b2"""
result = self.doc_class(html)(data=data)
assert result == expected, result

def testBasicHTMLIn(self):
data=(
d(name='jim', age=39),
Expand Down

0 comments on commit 4bdf140

Please sign in to comment.