Fix tests and remove old code.
This commit is contained in:
parent
039795beb7
commit
98bab9b358
@ -284,20 +284,6 @@ class Item(RESTModelMixin, models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
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
|
@property
|
||||||
def title(self):
|
def title(self):
|
||||||
"""
|
"""
|
||||||
|
@ -62,7 +62,7 @@ class ListOfSpeakersSlide(ProjectorElement):
|
|||||||
yield speaker.user
|
yield speaker.user
|
||||||
|
|
||||||
def get_collection_elements_required_for_this(self, collection_element, config_entry):
|
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
|
# Full update if item changes because then we may have new
|
||||||
# candidates and therefor need new users.
|
# candidates and therefor need new users.
|
||||||
if collection_element == CollectionElement.from_values(Item.get_collection_string(), config_entry.get('id')):
|
if collection_element == CollectionElement.from_values(Item.get_collection_string(), config_entry.get('id')):
|
||||||
|
@ -16,6 +16,7 @@ from openslides.poll.models import (
|
|||||||
CollectDefaultVotesMixin,
|
CollectDefaultVotesMixin,
|
||||||
PublishPollMixin,
|
PublishPollMixin,
|
||||||
)
|
)
|
||||||
|
from openslides.utils.autoupdate import inform_changed_data
|
||||||
from openslides.utils.exceptions import OpenSlidesError
|
from openslides.utils.exceptions import OpenSlidesError
|
||||||
from openslides.utils.models import RESTModelMixin
|
from openslides.utils.models import RESTModelMixin
|
||||||
from openslides.utils.search import user_name_helper
|
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.
|
Delete the connection from the assignment to the user.
|
||||||
"""
|
"""
|
||||||
self.assignment_related_users.filter(user=user).delete()
|
self.assignment_related_users.filter(user=user).delete()
|
||||||
|
inform_changed_data(self)
|
||||||
|
|
||||||
def set_phase(self, phase):
|
def set_phase(self, phase):
|
||||||
"""
|
"""
|
||||||
|
@ -15,6 +15,19 @@ from .access_permissions import (
|
|||||||
from .exceptions import ProjectorException
|
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):
|
class Projector(RESTModelMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
Model for all projectors. At the moment we support only one projector,
|
Model for all projectors. At the moment we support only one projector,
|
||||||
@ -57,6 +70,8 @@ class Projector(RESTModelMixin, models.Model):
|
|||||||
"""
|
"""
|
||||||
access_permissions = ProjectorAccessPermissions()
|
access_permissions = ProjectorAccessPermissions()
|
||||||
|
|
||||||
|
objects = ProjectorManager()
|
||||||
|
|
||||||
config = JSONField()
|
config = JSONField()
|
||||||
|
|
||||||
scale = models.IntegerField(default=0)
|
scale = models.IntegerField(default=0)
|
||||||
|
@ -20,8 +20,7 @@ def delete_django_app_permissions(sender, **kwargs):
|
|||||||
Q(app_label='auth') |
|
Q(app_label='auth') |
|
||||||
Q(app_label='contenttypes') |
|
Q(app_label='contenttypes') |
|
||||||
Q(app_label='sessions'))
|
Q(app_label='sessions'))
|
||||||
for permission in Permission.objects.filter(content_type__in=contenttypes):
|
Permission.objects.filter(content_type__in=contenttypes).delete()
|
||||||
permission.delete()
|
|
||||||
|
|
||||||
|
|
||||||
def create_builtin_projection_defaults(**kwargs):
|
def create_builtin_projection_defaults(**kwargs):
|
||||||
|
@ -26,9 +26,10 @@ class TestProjectorDBQueries(TestCase):
|
|||||||
Tests that only the following db queries are done:
|
Tests that only the following db queries are done:
|
||||||
* 5 requests to get the session an the request user with its permissions,
|
* 5 requests to get the session an the request user with its permissions,
|
||||||
* 2 requests to get the list of all projectors,
|
* 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))
|
self.client.force_login(User.objects.get(pk=1))
|
||||||
with self.assertNumQueries(7):
|
with self.assertNumQueries(8):
|
||||||
self.client.get(reverse('projector-list'))
|
self.client.get(reverse('projector-list'))
|
||||||
|
|
||||||
def test_anonymous(self):
|
def test_anonymous(self):
|
||||||
@ -36,12 +37,13 @@ class TestProjectorDBQueries(TestCase):
|
|||||||
Tests that only the following db queries are done:
|
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 permission for anonymous (config and permissions)
|
||||||
* 2 requests to get the list of all projectors,
|
* 2 requests to get the list of all projectors,
|
||||||
|
* 1 request to get the list of the projector defaults and
|
||||||
|
|
||||||
* 11 requests for permissions.
|
* 11 requests for permissions.
|
||||||
|
|
||||||
TODO: The last 11 requests are a bug.
|
TODO: The last 11 requests are a bug.
|
||||||
"""
|
"""
|
||||||
with self.assertNumQueries(15):
|
with self.assertNumQueries(16):
|
||||||
self.client.get(reverse('projector-list'))
|
self.client.get(reverse('projector-list'))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user