~netlandish/django-wiki

8c585d84b5f3d4bfc07742585451afd0a31a723a — Benjamin Bach 6 years ago d13700b + 2a6cec2
Merge pull request #833 from atombrella/yield_from

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