~netlandish/django-wiki

2a6cec2df4e5bc8bf4f1d3fc3cf573b78b7f9b25 — Mads Jensen 6 years ago 2a1745c
Use yield from syntax introduced in Python 3.3.
2 files changed, 4 insertions(+), 8 deletions(-)

M src/wiki/models/article.py
M src/wiki/plugins/macros/mdx/toc.py
M src/wiki/models/article.py => src/wiki/models/article.py +3 -6
@@ 88,14 88,12 @@ class Article(models.Model):
    def ancestor_objects(self):
        """NB! This generator is expensive, so use it with care!!"""
        for obj in self.articleforobject_set.filter(is_mptt=True):
            for ancestor in obj.content_object.get_ancestors():
                yield ancestor
            yield from obj.content_object.get_ancestors()

    def descendant_objects(self):
        """NB! This generator is expensive, so use it with care!!"""
        for obj in self.articleforobject_set.filter(is_mptt=True):
            for descendant in obj.content_object.get_descendants():
                yield descendant
            yield from obj.content_object.get_descendants()

    def get_children(self, max_num=None, user_can_read=None, **kwargs):
        """NB! This generator is expensive, so use it with care!!"""


@@ 106,8 104,7 @@ class Article(models.Model):
                    **kwargs).can_read(user_can_read)
            else:
                objects = obj.content_object.get_children().filter(**kwargs)
            for child in objects.order_by(
                    'articles__article__current_revision__title'):
            for child in objects.order_by('articles__article__current_revision__title'):
                cnt += 1
                if max_num and cnt > max_num:
                    return

M src/wiki/plugins/macros/mdx/toc.py => src/wiki/plugins/macros/mdx/toc.py +1 -2
@@ 49,8 49,7 @@ def itertext(elem):
    if elem.text:
        yield elem.text
    for e in elem:
        for s in itertext(e):
            yield s
        yield from itertext(e)
        if e.tail:
            yield e.tail