Commit 088e2de5 by tschmidt-dev

moved article save and delete clear cache signal handlers to Article model

parent 217fea9b
......@@ -4,6 +4,7 @@ from django.contrib.contenttypes import generic
from django.contrib.auth.models import User, Group
from django.core.cache import cache
from django.db import models
from django.db.models.signals import post_save, pre_delete
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
......@@ -332,3 +333,22 @@ class ArticleRevision(BaseRevisionMixin, models.Model):
ordering = ('created',)
unique_together = ('article', 'revision_number')
######################################################
# 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 ancestor in article.ancestor_objects():
ancestor.article.clear_cache()
def on_article_save_clear_cache(instance, **kwargs):
_clear_ancestor_cache(instance.article)
post_save.connect(on_article_save_clear_cache, Article)
def on_article_delete_clear_cache(instance, **kwargs):
_clear_ancestor_cache(instance)
pre_delete.connect(on_article_delete_clear_cache, Article)
......@@ -236,12 +236,6 @@ class URLPath(MPTTModel):
# 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 ancestor in article.ancestor_objects():
ancestor.article.clear_cache()
# Just get this once
urlpath_content_type = None
......@@ -252,7 +246,6 @@ def on_article_relation_save(**kwargs):
urlpath_content_type = ContentType.objects.get_for_model(URLPath)
if instance.content_type == urlpath_content_type:
URLPath.objects.filter(id=instance.object_id).update(article=instance.article)
_clear_ancestor_cache(instance.article)
post_save.connect(on_article_relation_save, ArticleForObject)
......@@ -295,6 +288,4 @@ def on_article_delete(instance, *args, **kwargs):
child.move_to(get_lost_and_found())
# ...and finally delete the path itself
_clear_ancestor_cache(instance)
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