Merge pull request #6148 from FinnStutzenstein/fixExporter

Fix OS4 exporter
This commit is contained in:
Emanuel Schütze 2021-07-08 14:13:22 +02:00 committed by GitHub
commit c593599e10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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"