OpenSlides/openslides/core/signals.py

80 lines
2.7 KiB
Python
Raw Normal View History

from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.db.models import Q
from django.dispatch import Signal
2016-09-12 11:05:34 +02:00
from .models import ProjectionDefault, Projector
# This signal is sent when the migrate command is done. That means it is sent
# after post_migrate sending and creating all Permission objects. Don't use it
# for other things than dealing with Permission objects.
post_permission_creation = Signal()
def delete_django_app_permissions(sender, **kwargs):
"""
Deletes the permissions, Django creates by default. Only required
for auth, contenttypes and sessions.
"""
contenttypes = ContentType.objects.filter(
Q(app_label='auth') |
Q(app_label='contenttypes') |
Q(app_label='sessions'))
for permission in Permission.objects.filter(content_type__in=contenttypes):
permission.delete()
2016-09-12 11:05:34 +02:00
def create_builtin_projection_defaults(**kwargs):
"""
Creates the builtin defaults:
- agenda_all_items, agenda_list_of_speakers, agenda_current_list_of_speakers
- topics
2016-09-12 11:05:34 +02:00
- assignments
- mediafiles
- motion
- users
These strings have to be used in the controllers where you want to
define a projector button. Use the string to get the id of the
responsible projector and pass this id to the projector button directive.
"""
# Check whether ProjectionDefault objects exist.
2016-09-12 11:05:34 +02:00
if ProjectionDefault.objects.all().exists():
# Do completely nothing if some defaults are already in the database.
2016-09-12 11:05:34 +02:00
return
default_projector = Projector.objects.get(pk=1)
ProjectionDefault.objects.create(
name='agenda_all_items',
display_name='Agenda',
projector=default_projector)
ProjectionDefault.objects.create(
name='topics',
display_name='Topics',
projector=default_projector)
ProjectionDefault.objects.create(
name='agenda_list_of_speakers',
2016-09-12 11:05:34 +02:00
display_name='List of speakers',
projector=default_projector)
ProjectionDefault.objects.create(
name='agenda_current_list_of_speakers',
2016-09-12 11:05:34 +02:00
display_name='Current list of speakers',
projector=default_projector)
ProjectionDefault.objects.create(
name='motions',
display_name='Motions',
projector=default_projector)
ProjectionDefault.objects.create(
name='assignments',
display_name='Elections',
projector=default_projector)
ProjectionDefault.objects.create(
name='users',
display_name='Participants',
projector=default_projector)
ProjectionDefault.objects.create(
name='mediafiles',
display_name='Files',
projector=default_projector)