Permalink
Browse files

Merge pull request #96 from LeResKP/develop

Be able to put an HTML separator between the children of a RepeatingWidget
  • Loading branch information...
ralphbean committed Sep 20, 2013
2 parents 30ea639 + db71764 commit 41229bf01b079f49d4ba8747d2f530f4d0eddf99
@@ -295,7 +295,7 @@ class TestCompoundWidget(tb.WidgetTest):
class RepeatingTestWidget(wd.RepeatingWidget):
child = AlwaysValidateFalseWidget
class TestRepeatingWidget(tb.WidgetTest):
class TestRepeatingTestWidget(tb.WidgetTest):
widget = RepeatingTestWidget
attrs = {'id':"rw", 'repetitions':1, 'validator':AlwaysValidateFalseValidator}
expected = """<div id="rw"><p>Test Widget</p></div>"""
@@ -320,11 +320,28 @@ class DummyRepeatingTestWidget(wd.RepeatingWidget):
children=[DummyWidget()]
w = DummyRepeatingTestWidget()
def test_separator(self):
widget = RepeatingTestWidget
attrs = {
'id': "rw",
'repetitions': 3,
'validator': AlwaysValidateFalseValidator,
'separator': '<hr />'}
params = {'separator': '<hr />'}
expected = ('<div id="rw">'
'<p>Test Widget</p><hr />'
'<p>Test Widget</p><hr />'
'<p>Test Widget</p>'
'</div>')
for engine in self._get_all_possible_engines():
yield (self._check_rendering_vs_expected,
engine, attrs, params, expected)
class DisplayOnlyTestWidget(wd.DisplayOnlyWidget):
child = twc.Variable(default=AlwaysValidateFalseWidget)
template = "tw2.core.test_templates.display_only_test_widget"
class TestDisplayOnlyWidget(tb.WidgetTest):
class TestDisplayOnlyTestWidget(tb.WidgetTest):
widget = DisplayOnlyTestWidget
attrs = {'id':"dotw"}
expected = """<p>Test Widget</p>"""
@@ -1,3 +1,8 @@
<?python
num = len(w.children)
?>
<div xmlns:py="http://genshi.edgewall.org/" py:attrs="w.attrs">
<py:for each="c in w.children">${c.display()}</py:for>
</div>
<py:for each="i,c in enumerate(w.children)">${c.display()}
<py:if test="w.separator and i != (num-1)">${w.separator}</py:if>
</py:for>
</div>
@@ -1,5 +1,6 @@
<div {{w.attrs | xmlattr }}>
{% for c in w.children %}
{{c.display()}}
{% if w.separator and not loop.last %}{{w.separator|safe}}{% endif %}
{% endfor %}
</div>
@@ -1,3 +1,8 @@
<?python
num = len(w.children)
?>
<div xmlns:py="http://genshi.edgewall.org/" py:attrs="w.attrs">
<py:for each="c in w.children">${c.display()}</py:for>
</div>
<py:for each="i,c in enumerate(w.children)">${c.display()}
<py:if test="w.separator and i != (num-1)">${w.separator}</py:if>
</py:for>
</div>
@@ -9,6 +9,9 @@ if 'class' in attr_keys:
<%namespace name="tw" module="tw2.core.mako_util"/>\
<div ${tw.attrs(attrs=w.attrs)}>
% for c in w.children:
${c.display() | n}
${c.display() | n}
% if w.separator and not loop.last:
${w.separator |n}
%endif
% endfor
</div>
@@ -1,6 +1,6 @@
<div tal:define="compile import: tw2.core.mako_util" tal:omit-tag=""></div>
<div tal:attributes="id w.attrs.get('id')"><span
tal:repeat="c w.children"
tal:content="structure c.display()"
tal:omit-tag=""
></span></div>
<div tal:attributes="id w.attrs.get('id')">
<loop tal:repeat="c w.children" tal:omit-tag="">
<span tal:replace="c.display()"></span>
<span tal:condition="w.separator and not repeat.c.end" tal:replace="structure w.separator"></span>
</loop></div>
@@ -15,6 +15,7 @@
from . import params as pm
import six
from six.moves import filter
from markupsafe import Markup
try:
import formencode
@@ -577,6 +578,8 @@ class CompoundWidget(Widget):
"CompoundWidgets that have no id",
)
template = 'tw2.core.templates.display_children'
separator = pm.Param('HTML snippet which will be inserted '
'between each repeated child', default=None)
@classmethod
def post_define(cls):
@@ -617,6 +620,8 @@ def prepare(self):
Propagate the value for this widget to the children, based on their id.
"""
super(CompoundWidget, self).prepare()
if self.separator:
self.separator = Markup(self.separator)
v = self.value or {}
if not hasattr(self, '_validated'):
if hasattr(v, '__getitem__'):
@@ -788,6 +793,8 @@ class RepeatingWidget(Widget):
repetition = pm.ChildVariable('The repetition of a child widget.')
template = 'tw2.core.templates.display_children'
separator = pm.Param('HTML snippet which will be inserted '
'between each repeated child', default=None)
@classmethod
def post_define(cls):
@@ -821,6 +828,8 @@ def prepare(self):
index.
"""
super(RepeatingWidget, self).prepare()
if self.separator:
self.separator = Markup(self.separator)
value = self.value or []
if self.repetitions is None:
reps = len(value) + self.extra_reps

0 comments on commit 41229bf

Please sign in to comment.