Fix OS4 exporter

This commit is contained in:
Finn Stutzenstein 2021-07-08 11:29:54 +02:00
parent 19a9eedf17
commit d17a050d8b
No known key found for this signature in database
GPG Key ID: 9042F605C6324654
2 changed files with 15 additions and 3 deletions

View File

@ -9,7 +9,10 @@ from django.conf import settings
from django.db import connections
from openslides.mediafiles.models import Mediafile
from openslides.mediafiles.views import use_mediafile_database
from openslides.mediafiles.views import (
mediafile_database_tablename,
use_mediafile_database,
)
from openslides.motions.models import Motion
from openslides.users.views import demo_mode_users, is_demo_mode
from openslides.utils.cache import element_cache
@ -205,6 +208,9 @@ class OS4Exporter:
def get_model(self, collection, id):
return self.data[collection][id]
def exists_model(self, collection, id):
return id in self.data[collection]
def iter_collection(self, collection):
return self.data[collection].values()
@ -633,7 +639,8 @@ class OS4Exporter:
if use_mediafile_database:
with connections["mediafiles"].cursor() as cursor:
cursor.execute(
"SELECT data FROM mediafile_data WHERE id = %s", [old["id"]]
f"SELECT data FROM {mediafile_database_tablename} WHERE id = %s",
[old["id"]],
)
row = cursor.fetchone()
if row is None:
@ -698,7 +705,8 @@ class OS4Exporter:
]
new["origin_id"] = None
new["derived_motion_ids"] = []
new["forwarding_tree_motion_ids"] = []
new["all_origin_ids"] = []
new["all_derived_motion_ids"] = []
new["block_id"] = old["motion_block_id"]
new["submitter_ids"] = self.create_motion_submitters(old["submitters"])
new["supporter_ids"] = old["supporters_id"]
@ -993,6 +1001,9 @@ class OS4Exporter:
notes = old.get("notes", {}).get("motions/motion", {})
for motion_id, note in notes.items():
motion_id = int(motion_id)
if not self.exists_model("motion", motion_id):
continue
new = {
"id": id_counter,
"user_id": old["user_id"],

View File

@ -27,6 +27,7 @@ from .utils import bytes_to_human, get_pdf_information
logger = logging.getLogger(__name__)
use_mediafile_database = "mediafiles" in connections
mediafile_database_tablename = None
if use_mediafile_database:
mediafile_database_tablename = (
settings.MEDIAFILE_DATABASE_TABLENAME or "mediafile_data"