1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
4 from django.db import models
7 class Source(models.Model):
8 """A collection of books, which might be defined before publishing them."""
9 netloc = models.CharField('położenie sieciowe', max_length=120, primary_key=True)
10 name = models.CharField('nazwa', max_length=120, blank=True)
13 ordering = ('netloc',)
14 verbose_name = 'źródło'
15 verbose_name_plural = 'źródła'
16 app_label = 'catalogue'
21 def save(self, *args, **kwargs):
22 from catalogue.models import Book
25 old_self = type(self).objects.get(pk=self)
26 except type(self).DoesNotExist:
28 old_netloc = self.netloc
30 old_name = old_self.name
31 old_netloc = old_self.netloc
33 ret = super(Source, self).save(*args, **kwargs)
35 # If something really changed here, find relevant books
36 # and invalidate their cached includes.
37 if old_name != self.name or old_netloc != self.netloc:
38 for book in Book.objects.all():
39 source = book.get_extra_info_json().get('source_url', '')
40 if self.netloc in source or (old_netloc != self.netloc and old_netloc in source):