diff --git a/openslides/agenda/models.py b/openslides/agenda/models.py index 88b4d9579..12b921a67 100644 --- a/openslides/agenda/models.py +++ b/openslides/agenda/models.py @@ -284,20 +284,6 @@ class Item(RESTModelMixin, models.Model): def __str__(self): return self.title - def delete(self, with_children=False): - """ - Delete the Item. - - If with_children is True, all children of the item will be deleted as - well. If with_children is False, all children will be children of the - parent of the item. - """ - if not with_children: - for child in self.children.all(): - child.parent = self.parent - child.save() - super().delete() - @property def title(self): """ diff --git a/openslides/agenda/projector.py b/openslides/agenda/projector.py index b318ba5d6..e8ce31f5d 100644 --- a/openslides/agenda/projector.py +++ b/openslides/agenda/projector.py @@ -62,7 +62,7 @@ class ListOfSpeakersSlide(ProjectorElement): yield speaker.user def get_collection_elements_required_for_this(self, collection_element, config_entry): - output = super().get_collections_required_for_this(collection_element, config_entry) + output = super().get_collection_elements_required_for_this(collection_element, config_entry) # Full update if item changes because then we may have new # candidates and therefor need new users. if collection_element == CollectionElement.from_values(Item.get_collection_string(), config_entry.get('id')): diff --git a/openslides/assignments/models.py b/openslides/assignments/models.py index 98e63d3e4..40fe85a00 100644 --- a/openslides/assignments/models.py +++ b/openslides/assignments/models.py @@ -16,6 +16,7 @@ from openslides.poll.models import ( CollectDefaultVotesMixin, PublishPollMixin, ) +from openslides.utils.autoupdate import inform_changed_data from openslides.utils.exceptions import OpenSlidesError from openslides.utils.models import RESTModelMixin from openslides.utils.search import user_name_helper @@ -209,6 +210,7 @@ class Assignment(RESTModelMixin, models.Model): Delete the connection from the assignment to the user. """ self.assignment_related_users.filter(user=user).delete() + inform_changed_data(self) def set_phase(self, phase): """ diff --git a/openslides/core/models.py b/openslides/core/models.py index 926bc3073..bdb6d0c40 100644 --- a/openslides/core/models.py +++ b/openslides/core/models.py @@ -15,6 +15,19 @@ from .access_permissions import ( from .exceptions import ProjectorException +class ProjectorManager(models.Manager): + """ + Customized model manager to support our get_full_queryset method. + """ + def get_full_queryset(self): + """ + Returns the normal queryset with all projectors. In the background + projector defaults are prefetched from the database. + """ + return self.get_queryset().prefetch_related( + 'projectiondefaults') + + class Projector(RESTModelMixin, models.Model): """ Model for all projectors. At the moment we support only one projector, @@ -57,6 +70,8 @@ class Projector(RESTModelMixin, models.Model): """ access_permissions = ProjectorAccessPermissions() + objects = ProjectorManager() + config = JSONField() scale = models.IntegerField(default=0) diff --git a/openslides/core/signals.py b/openslides/core/signals.py index 92609c323..f2667ca21 100644 --- a/openslides/core/signals.py +++ b/openslides/core/signals.py @@ -20,8 +20,7 @@ def delete_django_app_permissions(sender, **kwargs): Q(app_label='auth') | Q(app_label='contenttypes') | Q(app_label='sessions')) - for permission in Permission.objects.filter(content_type__in=contenttypes): - permission.delete() + Permission.objects.filter(content_type__in=contenttypes).delete() def create_builtin_projection_defaults(**kwargs): diff --git a/tests/integration/core/test_viewset.py b/tests/integration/core/test_viewset.py index 926bfa39b..c1a803fa6 100644 --- a/tests/integration/core/test_viewset.py +++ b/tests/integration/core/test_viewset.py @@ -26,9 +26,10 @@ class TestProjectorDBQueries(TestCase): Tests that only the following db queries are done: * 5 requests to get the session an the request user with its permissions, * 2 requests to get the list of all projectors, + * 1 request to get the list of the projector defaults. """ self.client.force_login(User.objects.get(pk=1)) - with self.assertNumQueries(7): + with self.assertNumQueries(8): self.client.get(reverse('projector-list')) def test_anonymous(self): @@ -36,12 +37,13 @@ class TestProjectorDBQueries(TestCase): Tests that only the following db queries are done: * 2 requests to get the permission for anonymous (config and permissions) * 2 requests to get the list of all projectors, + * 1 request to get the list of the projector defaults and * 11 requests for permissions. TODO: The last 11 requests are a bug. """ - with self.assertNumQueries(15): + with self.assertNumQueries(16): self.client.get(reverse('projector-list'))