2013-09-07 00:18:13 +02:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2013-02-20 23:50:34 +01:00
|
|
|
|
2016-03-20 20:42:07 +01:00
|
|
|
from openslides.utils.autoupdate import inform_changed_data
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2013-09-25 10:01:01 +02:00
|
|
|
from .models import Item
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2013-02-20 23:50:34 +01:00
|
|
|
|
2015-10-24 19:02:43 +02:00
|
|
|
def listen_to_related_object_post_save(sender, instance, created, **kwargs):
|
2013-09-07 00:18:13 +02:00
|
|
|
"""
|
2015-10-24 19:02:43 +02:00
|
|
|
Receiver function to create agenda items. It is connected to the signal
|
|
|
|
django.db.models.signals.post_save during app loading.
|
2016-12-02 15:47:57 +01:00
|
|
|
|
|
|
|
Do not run caching and autoupdate if the instance as an attribute
|
|
|
|
skip_autoupdate (regardless of its truthy or falsy conent).
|
2015-10-24 19:02:43 +02:00
|
|
|
"""
|
2016-09-17 22:26:23 +02:00
|
|
|
if hasattr(instance, 'get_agenda_title'):
|
|
|
|
if created:
|
|
|
|
# If the object is created, the related_object has to be sent again.
|
|
|
|
Item.objects.create(content_object=instance)
|
2016-12-02 15:47:57 +01:00
|
|
|
if not hasattr(instance, 'skip_autoupdate'):
|
|
|
|
inform_changed_data(instance)
|
|
|
|
elif not hasattr(instance, 'skip_autoupdate'):
|
2016-09-17 22:26:23 +02:00
|
|
|
# If the object has changed, then also the agenda item has to be sent.
|
|
|
|
inform_changed_data(instance.agenda_item)
|
2015-10-24 19:02:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
def listen_to_related_object_post_delete(sender, instance, **kwargs):
|
|
|
|
"""
|
|
|
|
Receiver function to delete agenda items. It is connected to the signal
|
|
|
|
django.db.models.signals.post_delete during app loading.
|
2013-09-07 00:18:13 +02:00
|
|
|
"""
|
|
|
|
if hasattr(instance, 'get_agenda_title'):
|
2015-10-24 19:02:43 +02:00
|
|
|
content_type = ContentType.objects.get_for_model(instance)
|
|
|
|
try:
|
|
|
|
Item.objects.get(object_id=instance.pk, content_type=content_type).delete()
|
|
|
|
except Item.DoesNotExist:
|
|
|
|
# Item does not exist so we do not have to delete it.
|
|
|
|
pass
|