Commit e20b2d66 by tschmidt

clear ancestor cache on save and delete article so that things like article_lists are refreshed

parent 9ca892d8
...@@ -236,6 +236,13 @@ class URLPath(MPTTModel): ...@@ -236,6 +236,13 @@ class URLPath(MPTTModel):
# SIGNAL HANDLERS # SIGNAL HANDLERS
###################################################### ######################################################
# clear the ancestor cache when saving or deleting articles so things like
# article_lists will be refreshed
def _clear_ancestor_cache(article):
for urlpath in article.urlpath_set.all():
for ancestor in urlpath.get_ancestors():
ancestor.article.clear_cache()
# Just get this once # Just get this once
urlpath_content_type = None urlpath_content_type = None
...@@ -246,6 +253,7 @@ def on_article_relation_save(**kwargs): ...@@ -246,6 +253,7 @@ def on_article_relation_save(**kwargs):
urlpath_content_type = ContentType.objects.get_for_model(URLPath) urlpath_content_type = ContentType.objects.get_for_model(URLPath)
if instance.content_type == urlpath_content_type: if instance.content_type == urlpath_content_type:
URLPath.objects.filter(id=instance.object_id).update(article=instance.article) URLPath.objects.filter(id=instance.object_id).update(article=instance.article)
_clear_ancestor_cache(instance.article)
post_save.connect(on_article_relation_save, ArticleForObject) post_save.connect(on_article_relation_save, ArticleForObject)
...@@ -287,5 +295,7 @@ def on_article_delete(instance, *args, **kwargs): ...@@ -287,5 +295,7 @@ def on_article_delete(instance, *args, **kwargs):
for child in urlpath.get_children(): for child in urlpath.get_children():
child.move_to(get_lost_and_found()) child.move_to(get_lost_and_found())
# ...and finally delete the path itself # ...and finally delete the path itself
_clear_ancestor_cache(instance)
pre_delete.connect(on_article_delete, Article) pre_delete.connect(on_article_delete, Article)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment