Show More
@@ -350,6 +350,7 b' def stringify(thing):' | |||||
350 | """Any type. Turns the value into text by converting values into |
|
350 | """Any type. Turns the value into text by converting values into | |
351 | text and concatenating them. |
|
351 | text and concatenating them. | |
352 | """ |
|
352 | """ | |
|
353 | thing = templatekw.unwraphybrid(thing) | |||
353 | if util.safehasattr(thing, '__iter__') and not isinstance(thing, str): |
|
354 | if util.safehasattr(thing, '__iter__') and not isinstance(thing, str): | |
354 | return "".join([stringify(t) for t in thing if t is not None]) |
|
355 | return "".join([stringify(t) for t in thing if t is not None]) | |
355 | if thing is None: |
|
356 | if thing is None: |
@@ -35,8 +35,6 b' class _hybrid(object):' | |||||
35 | self.values = values |
|
35 | self.values = values | |
36 | self._makemap = makemap |
|
36 | self._makemap = makemap | |
37 | self.joinfmt = joinfmt |
|
37 | self.joinfmt = joinfmt | |
38 | def __iter__(self): |
|
|||
39 | return self.gen |
|
|||
40 | def itermaps(self): |
|
38 | def itermaps(self): | |
41 | makemap = self._makemap |
|
39 | makemap = self._makemap | |
42 | for x in self.values: |
|
40 | for x in self.values: | |
@@ -50,6 +48,13 b' class _hybrid(object):' | |||||
50 | raise AttributeError(name) |
|
48 | raise AttributeError(name) | |
51 | return getattr(self.values, name) |
|
49 | return getattr(self.values, name) | |
52 |
|
50 | |||
|
51 | def unwraphybrid(thing): | |||
|
52 | """Return an object which can be stringified possibly by using a legacy | |||
|
53 | template""" | |||
|
54 | if not util.safehasattr(thing, 'gen'): | |||
|
55 | return thing | |||
|
56 | return thing.gen | |||
|
57 | ||||
53 | def showlist(name, values, plural=None, element=None, separator=' ', **args): |
|
58 | def showlist(name, values, plural=None, element=None, separator=' ', **args): | |
54 | if not element: |
|
59 | if not element: | |
55 | element = name |
|
60 | element = name |
@@ -1020,6 +1020,7 b' stringify = templatefilters.stringify' | |||||
1020 |
|
1020 | |||
1021 | def _flatten(thing): |
|
1021 | def _flatten(thing): | |
1022 | '''yield a single stream from a possibly nested set of iterators''' |
|
1022 | '''yield a single stream from a possibly nested set of iterators''' | |
|
1023 | thing = templatekw.unwraphybrid(thing) | |||
1023 | if isinstance(thing, str): |
|
1024 | if isinstance(thing, str): | |
1024 | yield thing |
|
1025 | yield thing | |
1025 | elif thing is None: |
|
1026 | elif thing is None: | |
@@ -1028,6 +1029,7 b' def _flatten(thing):' | |||||
1028 | yield str(thing) |
|
1029 | yield str(thing) | |
1029 | else: |
|
1030 | else: | |
1030 | for i in thing: |
|
1031 | for i in thing: | |
|
1032 | i = templatekw.unwraphybrid(i) | |||
1031 | if isinstance(i, str): |
|
1033 | if isinstance(i, str): | |
1032 | yield i |
|
1034 | yield i | |
1033 | elif i is None: |
|
1035 | elif i is None: |
General Comments 0
You need to be logged in to leave comments.
Login now