Skip to content
Snippets Groups Projects
Commit f1f27d07 authored by Simon Künzel's avatar Simon Künzel
Browse files

Small adjustments to objects

parent 10eaf701
No related branches found
No related tags found
No related merge requests found
import os
from pathlib import Path
from videoag_common.miscellaneous.util import load_config_file, merge_config_with
from videoag_common.miscellaneous.util import load_config_file, merge_config_into
if "VIDEOAG_CONFIG" not in os.environ:
raise Exception("Missing VIDEOAG_CONFIG environment variable")
config = load_config_file(Path(os.getcwd()).joinpath(os.environ["VIDEOAG_CONFIG"]))
if "VIDEOAG_TEST_CONFIG_OVERRIDE" in os.environ:
merge_config_with(
merge_config_into(
config,
load_config_file(Path(os.getcwd()).joinpath(os.environ["VIDEOAG_TEST_CONFIG_OVERRIDE"]))
load_config_file(Path(os.getcwd()).joinpath(os.environ["VIDEOAG_TEST_CONFIG_OVERRIDE"])),
overwrite_non_mergeable=True
)
......@@ -114,12 +114,12 @@ def load_config_file(path: Path):
return config
def merge_config_with(config: dict, to_merge: dict, overwrite_non_mergeable: bool = False):
def merge_config_into(config: dict, to_merge: dict, overwrite_non_mergeable: bool = False):
for key, item in to_merge.items():
if key not in config:
config[key] = item
elif isinstance(item, dict) and isinstance(config[key], dict):
merge_config_with(config[key], item)
merge_config_into(config[key], item, overwrite_non_mergeable=overwrite_non_mergeable)
elif overwrite_non_mergeable:
config[key] = item
else:
......
......@@ -20,6 +20,7 @@ from .medium import (
ThumbnailTargetMedium,
SourceMedium,
SourceMediumStatus,
MediaProcessTemplate,
LOAD_SOURCE_MEDIUM_LECTURE,
LOAD_PUBLISH_MEDIUM_LECTURE,
LOAD_PUBLISH_MEDIUM_TARGET_MEDIUM,
......
......@@ -88,7 +88,8 @@ class ChangelogModificationEntry(ChangelogEntry):
old_value: Mapped[dict] = api_mapped(
mapped_column(sql.types.JSON(), nullable=True),
ApiJsonField(
include_in_data=True, data_notes="Note that this may contain arbitrary json due to legacy values"
include_in_data=True, data_if=lambda entry, args: entry.old_value is not None,
data_notes="Note that this may contain arbitrary json due to legacy values. Not present if this was at creation"
)
)
new_value: Mapped[dict] = api_mapped(
......
......@@ -134,7 +134,7 @@ class Lecture(DeletableApiObject, VisibilityApiObject, ApiViewPermissionsObject,
publish_time: Mapped[datetime] = api_mapped(
mapped_column(TIMESTAMP(), nullable=True, index=True),
ApiDatetimeField(
include_in_data=True
include_in_data=True, data_only_mod=True
)
)
media_process: Mapped[dict] = api_mapped(
......@@ -467,11 +467,13 @@ class Course(DeletableApiObject, VisibilityApiObject, ApiViewPermissionsObject,
lectures: Mapped[list[Lecture]] = relationship(
back_populates="course",
primaryjoin=lambda: sql.and_(Lecture.course_id == Course.id, Lecture.has_access(is_mod=True, from_course=True)),
order_by=Lecture.time.asc(),
lazy="raise_on_sql"
)
public_lectures: Mapped[list[Lecture]] = relationship(
back_populates="course",
primaryjoin=lambda: sql.and_(Lecture.course_id == Course.id, Lecture.has_access(is_mod=False, from_course=True)),
order_by=Lecture.time.asc(),
lazy="raise_on_sql",
viewonly=True
)
......@@ -492,7 +494,8 @@ class Course(DeletableApiObject, VisibilityApiObject, ApiViewPermissionsObject,
type_id="lecture[]",
data_id="lectures",
data_if=lambda course, args: args.include_lectures,
data_notes="Only present if requested. All (public) lectures. Lectures will include chapters and media_sources"
data_notes="Only present if requested. All (public) lectures. Sorted by their time ascending. Lectures will "
"include chapters and publish media"
)
def _data_lectures(self, is_mod: bool):
return self.lectures if is_mod else self.public_lectures
......
......@@ -558,13 +558,15 @@ class MediaProcessTemplate(ApiObject, Base):
mapped_column(String(collation=STRING_COLLATION), nullable=False),
ApiStringField(
max_length=256,
include_in_config=True
include_in_config=True, config_directly_modifiable=True,
include_in_data=True
)
)
process: Mapped[dict] = api_mapped(
mapped_column(postgresql.JSONB, nullable=False),
ApiMediaProcessField(
include_in_config=True
include_in_config=True, config_directly_modifiable=True,
include_in_data=True
)
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment