Mercurial > p > roundup > code
diff roundup/cgi/ZTUtils/Iterator.py @ 7866:9bbc1d951677
issue2551331 - Fix repeat first/last methods.
The first() and last() methods for a variable defined by tal:repeat
now work as documented.
There is an undocumented same_part() method for repeat. It is called
by first/last and can cause them to return true when not at an end of
the Iterator sequence. I wrote a treatise on that function and what it
does. I have no idea why it does what it does.
Added tests for roundup/cgi/ZTUtils/Iterator.py
Also fixes issue with roman() found while writing tests. lower wasn't
being called and it was printing the lower() method signature.
Doc updates in references.txt to come in a future checkin. Clarifying
the repeat methods led to finding/fixing this.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 07 Apr 2024 20:52:17 -0400 |
| parents | ef6631409171 |
| children | fed0f839c260 |
line wrap: on
line diff
--- a/roundup/cgi/ZTUtils/Iterator.py Sun Apr 07 15:33:33 2024 -0400 +++ b/roundup/cgi/ZTUtils/Iterator.py Sun Apr 07 20:52:17 2024 -0400 @@ -85,17 +85,42 @@ return s def roman(self, lower=lambda x:x.lower): - return lower(self.Roman()) + return self.Roman().lower() def first(self, name=None): if self.start: return 1 - return not self.same_part(name, self._last, self.item) + return self.same_part(name, self._last, self.item) def last(self, name=None): if self.end: return 1 - return not self.same_part(name, self.item, self._next) + return self.same_part(name, self.item, self._next) def same_part(self, name, ob1, ob2): + """I have no idea what this does. + + It returns True for first()/last() when there are more items + in the sequence. Called by first() to compare the previous + item in sequence and the current item. Caled by last() to + compare the current item and next item in sequence. + + Accepts a string version of the name of an attribute as 'name'. + + If no attribute name is provided, return True if the two items: + + are equal (==) - duplicate strings/integer/same object + + else False. + + If a non-existent attribute name is provided return False. + + If the attribute is present and the named attributes compare + equal (==) return True else False. + + No idea what use case this handles. Maybe this has + something to do with batching and first/last returning True + triggers a new group? + """ + if name is None: return ob1 == ob2 no = []
