2017-03-07 10:23:24 +01:00
|
|
|
from django.apps import apps
|
2013-09-07 00:18:13 +02:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2013-02-20 23:50:34 +01:00
|
|
|
|
2013-09-25 10:01:01 +02:00
|
|
|
from .models import Item
|
2019-03-04 18:40:08 +01:00
|
|
|
from ..utils.autoupdate import inform_changed_data
|
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
|
|
|
|
2017-08-03 15:49:14 +02:00
|
|
|
The agenda_item_update_information container may have fields like type,
|
2018-01-20 09:54:46 +01:00
|
|
|
parent_id, comment, duration, weight or skip_autoupdate.
|
2017-08-03 15:49:14 +02:00
|
|
|
|
2018-01-20 09:54:46 +01:00
|
|
|
Do not run caching and autoupdate if the instance has a key
|
2017-08-03 15:49:14 +02:00
|
|
|
skip_autoupdate in the agenda_item_update_information container.
|
2015-10-24 19:02:43 +02:00
|
|
|
"""
|
2019-02-15 12:17:08 +01:00
|
|
|
if hasattr(instance, "get_agenda_title_information"):
|
2016-09-17 22:26:23 +02:00
|
|
|
if created:
|
2017-08-03 15:49:14 +02:00
|
|
|
attrs = {}
|
2019-01-06 16:22:33 +01:00
|
|
|
for attr in ("type", "parent_id", "comment", "duration", "weight"):
|
2018-01-20 09:54:46 +01:00
|
|
|
if instance.agenda_item_update_information.get(attr):
|
|
|
|
attrs[attr] = instance.agenda_item_update_information.get(attr)
|
2017-08-03 15:49:14 +02:00
|
|
|
Item.objects.create(content_object=instance, **attrs)
|
|
|
|
|
2016-09-17 22:26:23 +02:00
|
|
|
# If the object is created, the related_object has to be sent again.
|
2019-01-06 16:22:33 +01:00
|
|
|
if not instance.agenda_item_update_information.get("skip_autoupdate"):
|
2016-12-02 15:47:57 +01:00
|
|
|
inform_changed_data(instance)
|
2019-01-06 16:22:33 +01:00
|
|
|
elif not instance.agenda_item_update_information.get("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
|
|
|
"""
|
2019-02-25 11:12:58 +01:00
|
|
|
if hasattr(instance, "get_agenda_title_information"):
|
2015-10-24 19:02:43 +02:00
|
|
|
content_type = ContentType.objects.get_for_model(instance)
|
|
|
|
try:
|
2017-07-28 15:42:58 +02:00
|
|
|
# Attention: This delete() call is also necessary to remove
|
|
|
|
# respective active list of speakers projector elements.
|
2015-10-24 19:02:43 +02:00
|
|
|
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
|
2017-03-07 10:23:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_permission_change_data(sender, permissions, **kwargs):
|
|
|
|
"""
|
|
|
|
Yields all necessary collections if 'agenda.can_see' or
|
2018-08-15 11:15:54 +02:00
|
|
|
'agenda.can_see_internal_items' permissions changes.
|
2017-03-07 10:23:24 +01:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
agenda_app = apps.get_app_config(app_label="agenda")
|
2017-03-07 10:23:24 +01:00
|
|
|
for permission in permissions:
|
|
|
|
# There could be only one 'agenda.can_see' and then we want to return data.
|
2019-01-06 16:22:33 +01:00
|
|
|
if (
|
|
|
|
permission.content_type.app_label == agenda_app.label
|
|
|
|
and permission.codename in ("can_see", "can_see_internal_items")
|
|
|
|
):
|
2017-03-07 10:23:24 +01:00
|
|
|
yield from agenda_app.get_startup_elements()
|
|
|
|
break
|