From 10b367c03d1e3a8ad6e365b02a7234bfd640e3f6 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Wed, 4 Jul 2018 09:23:42 +0200 Subject: [PATCH 1/1] clear cached template fragments on book save --- src/catalogue/fields.py | 5 ++++- src/catalogue/signals.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/catalogue/fields.py b/src/catalogue/fields.py index 1ed34e2c5..92e8de48c 100644 --- a/src/catalogue/fields.py +++ b/src/catalogue/fields.py @@ -109,9 +109,12 @@ class BuildEbook(Task): fieldfile.save(None, File(open(out.get_filename())), save=False) self.set_file_permissions(fieldfile) if book.pk is not None: - type(book).objects.filter(pk=book.pk).update(**{ + books = type(book).objects.filter(pk=book.pk) + books.update(**{ fieldfile.field.attname: fieldfile }) + for book in books: + book.save() # just to trigger post-save if fieldfile.field.format_name in app_settings.FORMAT_ZIPS: remove_zip(app_settings.FORMAT_ZIPS[fieldfile.field.format_name]) # Don't decorate BuildEbook, because we want to subclass it. diff --git a/src/catalogue/signals.py b/src/catalogue/signals.py index f3cacaaf7..28d84bece 100644 --- a/src/catalogue/signals.py +++ b/src/catalogue/signals.py @@ -4,6 +4,7 @@ # 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 ssify import flush_ssi_includes @@ -51,6 +52,11 @@ def collection_delete(sender, instance, **kwargs): def book_save(sender, instance, **kwargs): # Books come out anywhere. caches[settings.CACHE_MIDDLEWARE_ALIAS].clear() + # deleting selectively is too much work + try: + caches['template_fragments'].clear() + except ImproperlyConfigured: + pass instance.flush_includes() -- 2.20.1