OpenSlides/openslides/agenda/signals.py
Oskar Hahn 6abb0976c2 Change system for autoupdate on the projector (#2394)
* Second websocket channel for the projector

* Removed use of projector requirements for REST API requests.

Refactored data serializing for projector websocket connection.

* Refactor the way that the projector autoupdate get its data.

* Fixed missing assignment slide title for hidden items.

* Release all items for item list slide and list of speakers slide. Fixed error with motion workflow.

* Created CollectionElement class which helps to handle autoupdate.
2016-09-17 22:26:23 +02:00

35 lines
1.3 KiB
Python

from django.contrib.contenttypes.models import ContentType
from openslides.utils.autoupdate import inform_changed_data
from .models import Item
def listen_to_related_object_post_save(sender, instance, created, **kwargs):
"""
Receiver function to create agenda items. It is connected to the signal
django.db.models.signals.post_save during app loading.
"""
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)
inform_changed_data(instance)
else:
# If the object has changed, then also the agenda item has to be sent.
inform_changed_data(instance.agenda_item)
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.
"""
if hasattr(instance, 'get_agenda_title'):
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