1 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django.contrib.auth.models import User
5 from django.db import models
7 from documents.models import (Book, Chunk, Image, BookPublishRecord,
9 from documents.signals import post_publish
10 from dvcs.signals import post_publishable
13 def book_changed(sender, instance, created, **kwargs):
17 models.signals.post_save.connect(book_changed, sender=Book)
20 def chunk_changed(sender, instance, created, **kwargs):
23 models.signals.post_save.connect(chunk_changed, sender=Chunk)
26 def image_changed(sender, instance, created, **kwargs):
28 models.signals.post_save.connect(image_changed, sender=Image)
31 def publish_listener(sender, *args, **kwargs):
32 if isinstance(sender, BookPublishRecord):
36 elif isinstance(sender, ImagePublishRecord):
38 post_publish.connect(publish_listener)
41 def chunk_publishable_listener(sender, *args, **kwargs):
43 if isinstance(sender.tree, Chunk):
44 sender.tree.book.touch()
45 post_publishable.connect(chunk_publishable_listener)
47 def publishable_listener(sender, *args, **kwargs):
49 post_publishable.connect(publishable_listener, sender=Image)
52 def listener_create(sender, instance, created, **kwargs):
54 instance.chunk_set.create(number=1, slug='1')
55 models.signals.post_save.connect(listener_create, sender=Book)
58 def cover_changed(sender, instance, created, **kwargs):
59 for book in instance.book_set.all():
61 models.signals.post_save.connect(cover_changed, sender=cover.models.Image)