From c13df51a67c7edd1d88ca5c95747dd6fcfe73ad7 Mon Sep 17 00:00:00 2001 From: Gustavo Andres Morero Date: Thu, 19 Jan 2017 13:13:49 -0300 Subject: [PATCH] org related updates to solve issues on article delete. --- wiki/models/urlpath.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/wiki/models/urlpath.py b/wiki/models/urlpath.py index d5e2f504..b1ad873c 100644 --- a/wiki/models/urlpath.py +++ b/wiki/models/urlpath.py @@ -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) -- 2.45.2