Used bulk_create to create the initial projector during migration. Fixed #2035.

This commit is contained in:
Norman Jäckel 2016-03-07 18:54:05 +01:00
parent ce3576f306
commit 56936c86ab

View File

@ -2,7 +2,6 @@
# Generated by Django 1.9.2 on 2016-03-02 01:22
from __future__ import unicode_literals
import json
import uuid
import django.db.models.deletion
@ -13,15 +12,21 @@ from django.db import migrations, models
import openslides.utils.models
def add_default_projector_via_sql():
def add_default_projector(apps, schema_editor):
"""
Adds default projector and activates clock.
"""
# We get the model from the versioned app registry;
# if we directly import it, it will be the wrong version.
Projector = apps.get_model('core', 'Projector')
projector_config = {}
projector_config[uuid.uuid4().hex] = {
'name': 'core/clock',
'stable': True}
return ["INSERT INTO core_projector (config, scale, scroll) VALUES ('{}', 0, 0);".format(json.dumps(projector_config))]
# We use bulk_create here because we do not want model's save() method
# to be called because we do not want our autoupdate signals to be
# triggered.
Projector.objects.bulk_create([Projector(config=projector_config)])
class Migration(migrations.Migration):
@ -105,5 +110,5 @@ class Migration(migrations.Migration):
},
bases=(openslides.utils.models.RESTModelMixin, models.Model),
),
migrations.RunSQL(add_default_projector_via_sql()),
migrations.RunPython(add_default_projector),
]