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
6 from documents.models import (Book, Chunk, Image, BookPublishRecord,
8 from documents.signals import post_publish
9 from dvcs.signals import post_publishable
12 def book_changed(sender, instance, created, **kwargs):
16 models.signals.post_save.connect(book_changed, sender=Book)
19 def chunk_changed(sender, instance, created, **kwargs):
22 models.signals.post_save.connect(chunk_changed, sender=Chunk)
25 def image_changed(sender, instance, created, **kwargs):
27 models.signals.post_save.connect(image_changed, sender=Image)
30 def publish_listener(sender, *args, **kwargs):
31 if isinstance(sender, BookPublishRecord):
35 elif isinstance(sender, ImagePublishRecord):
37 post_publish.connect(publish_listener)
40 def chunk_publishable_listener(sender, *args, **kwargs):
42 if isinstance(sender.tree, Chunk):
43 sender.tree.book.touch()
44 post_publishable.connect(chunk_publishable_listener)
46 def publishable_listener(sender, *args, **kwargs):
48 post_publishable.connect(publishable_listener, sender=Image)
51 def listener_create(sender, instance, created, **kwargs):
53 instance.chunk_set.create(number=1, slug='1')
54 models.signals.post_save.connect(listener_create, sender=Book)