~netlandish/django-wiki

c13df51a67c7edd1d88ca5c95747dd6fcfe73ad7 — Gustavo Andres Morero 7 years ago 1b92f92
org related updates to solve issues on article delete.
1 files changed, 8 insertions(+), 5 deletions(-)

M wiki/models/urlpath.py
M wiki/models/urlpath.py => wiki/models/urlpath.py +8 -5
@@ 351,19 351,21 @@ def on_article_delete(instance, *args, **kwargs):
    ns = Namespace()   # nonlocal namespace backported to Python 2.x
    ns.lost_and_found = None

    def get_lost_and_found():
    def get_lost_and_found(org=None):
        if ns.lost_and_found:
            return ns.lost_and_found
        try:
            parent = URLPath.root(org) if org else URLPath.root()
            ns.lost_and_found = URLPath.objects.get(
                slug=settings.LOST_AND_FOUND_SLUG,
                parent=URLPath.root(),
                parent=parent,
                site=site)
        except URLPath.DoesNotExist:
            article = Article(group_read=True,
                              group_write=False,
                              other_read=False,
                              other_write=False)
                              other_write=False,
                              organization=org)
            article.add_revision(
                ArticleRevision(
                    content=_(


@@ 371,9 373,10 @@ def on_article_delete(instance, *args, **kwargs):
                        '===============================\n\n'
                        'The children of this article have had their parents deleted. You should probably find a new home for them.'),
                    title=_("Lost and found")))
            parent = URLPath.root(org) if org else URLPath.root()
            ns.lost_and_found = URLPath.objects.create(
                slug=settings.LOST_AND_FOUND_SLUG,
                parent=URLPath.root(),
                parent=parent,
                site=site,
                article=article)
            article.add_object_relation(ns.lost_and_found)


@@ 384,7 387,7 @@ def on_article_delete(instance, *args, **kwargs):
            site=site):
        # Delete the children
        for child in urlpath.get_children():
            child.move_to(get_lost_and_found())
            child.move_to(get_lost_and_found(instance.organization))
        # ...and finally delete the path itself

pre_delete.connect(on_article_delete, Article)