Add basic login.
[wolnelektury.git] / src / catalogue / signals.py
index f3cacaa..8bbc0bf 100644 (file)
@@ -1,14 +1,12 @@
-# -*- coding: utf-8 -*-
-# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
 #
 from django.conf import settings
 from django.core.cache import caches
 #
 from django.conf import settings
 from django.core.cache import caches
+from django.core.exceptions import ImproperlyConfigured
 from django.db.models.signals import post_save, post_delete
 from django.dispatch import receiver
 from django.db.models.signals import post_save, post_delete
 from django.dispatch import receiver
-from ssify import flush_ssi_includes
 from newtagging.models import tags_updated
 from newtagging.models import tags_updated
-from picture.models import Picture, PictureArea
 from .models import BookMedia, Book, Collection, Fragment, Tag
 
 
 from .models import BookMedia, Book, Collection, Fragment, Tag
 
 
@@ -31,17 +29,8 @@ def bookmedia_save(sender, instance, **kwargs):
 @receiver(post_save, sender=Collection)
 def collection_save(sender, instance, **kwargs):
     caches[settings.CACHE_MIDDLEWARE_ALIAS].clear()
 @receiver(post_save, sender=Collection)
 def collection_save(sender, instance, **kwargs):
     caches[settings.CACHE_MIDDLEWARE_ALIAS].clear()
-    flush_ssi_includes([
-        '/katalog/%s.json' % lang
-        for lang in [lc for (lc, _ln) in settings.LANGUAGES]])
 
 
 
 
-@receiver(post_delete, sender=Collection)
-def collection_delete(sender, instance, **kwargs):
-    flush_ssi_includes([
-        '/katalog/%s.json' % lang
-        for lang in [lc for (lc, _ln) in settings.LANGUAGES]])
-
 ####
 # Book
 ####
 ####
 # Book
 ####
@@ -51,22 +40,17 @@ def collection_delete(sender, instance, **kwargs):
 def book_save(sender, instance, **kwargs):
     # Books come out anywhere.
     caches[settings.CACHE_MIDDLEWARE_ALIAS].clear()
 def book_save(sender, instance, **kwargs):
     # Books come out anywhere.
     caches[settings.CACHE_MIDDLEWARE_ALIAS].clear()
-    instance.flush_includes()
+    # deleting selectively is too much work
+    try:
+        caches['template_fragments'].clear()
+    except ImproperlyConfigured:
+        pass
+    instance.clear_cache()
 
 
 @receiver(post_delete, sender=Book)
 def book_delete(sender, instance, **kwargs):
     caches[settings.CACHE_MIDDLEWARE_ALIAS].clear()
 
 
 @receiver(post_delete, sender=Book)
 def book_delete(sender, instance, **kwargs):
     caches[settings.CACHE_MIDDLEWARE_ALIAS].clear()
-    flush_ssi_includes([
-        '/katalog/%s.json' % lang
-        for lang in [lc for (lc, _ln) in settings.LANGUAGES]])
-
-    if not settings.NO_SEARCH_INDEX:
-        # remove the book from search index, when it is deleted.
-        from search.index import Index
-        idx = Index()
-        idx.remove_book(instance)
-        idx.index_tags()
 
 
 ####
 
 
 ####
@@ -75,20 +59,11 @@ def book_delete(sender, instance, **kwargs):
 
 
 @receiver(Tag.after_change)
 
 
 @receiver(Tag.after_change)
-def tag_after_change(sender, instance, languages, **kwargs):
+def tag_after_change(sender, instance, **kwargs):
     caches[settings.CACHE_MIDDLEWARE_ALIAS].clear()
     caches[settings.CACHE_MIDDLEWARE_ALIAS].clear()
-    flush_ssi_includes([
-        '/katalog/%s.json' % lang
-        for lang in [lc for (lc, _ln) in settings.LANGUAGES]])
-
-    for model in Book, Picture:
-        for model_instance in model.tagged.with_all([instance]).only('pk'):
-            model_instance.flush_includes()
 
 
-    if instance.category == 'author':
-        for model in Fragment, PictureArea:
-            for model_instance in model.tagged.with_all([instance]).only('pk'):
-                model_instance.flush_includes()
+    for book in Book.tagged.with_all([instance]).only('pk'):
+        book.clear_cache()
 
 
 @receiver(tags_updated)
 
 
 @receiver(tags_updated)
@@ -98,7 +73,5 @@ def receive_tags_updated(sender, instance, affected_tags, **kwargs):
         return
 
     caches[settings.CACHE_MIDDLEWARE_ALIAS].clear()
         return
 
     caches[settings.CACHE_MIDDLEWARE_ALIAS].clear()
-    instance.flush_includes()
-    flush_ssi_includes([
-        '/katalog/%s.json' % lang
-        for lang in [lc for (lc, _ln) in settings.LANGUAGES]])
+    if sender in (Book,):
+        instance.clear_cache()