X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/c3545c19bd62da303fe0f8c49f82d8c340d965ea..d3d0f68c842db9d5fda99a388f2df96358084166:/apps/catalogue/models/source.py?ds=inline diff --git a/apps/catalogue/models/source.py b/apps/catalogue/models/source.py index d13161378..9aff4efec 100644 --- a/apps/catalogue/models/source.py +++ b/apps/catalogue/models/source.py @@ -19,3 +19,27 @@ class Source(models.Model): def __unicode__(self): return self.netloc + + def save(self, *args, **kwargs): + from catalogue.models import Book + try: + str(self.pk) + old_self = type(self).objects.get(pk=self) + except type(self).DoesNotExist: + old_name = u'' + old_netloc = self.netloc + else: + old_name = old_self.name + old_netloc = old_self.netloc + + ret = super(Source, self).save(*args, **kwargs) + + # If something really changed here, find relevant books + # and invalidate their cached includes. + if old_name != self.name or old_netloc != self.netloc: + for book in Book.objects.all(): + source = book.extra_info.get('source_url', '') + if self.netloc in source or (old_netloc != self.netloc + and old_netloc in source): + book.flush_includes() + return ret