diff --git a/src/videoag_common/objects/medium.py b/src/videoag_common/objects/medium.py index 8a5e72291e571efeeca8d1c94b36853a43ca015d..fdcb44b9b1f80dda89984c0ca27676446f857312 100644 --- a/src/videoag_common/objects/medium.py +++ b/src/videoag_common/objects/medium.py @@ -156,6 +156,7 @@ class TargetMediumType(Enum): PLAIN_VIDEO = "plain_video" PLAIN_AUDIO = "plain_audio" THUMBNAIL = "thumbnail" + IMAGE = "image" _TARGET_MEDIUM_TYPE_ENUM = create_enum_type(TargetMediumType) @@ -194,12 +195,12 @@ class TargetMedium(DeletableApiObject, Base): name="check_audio_channel_count_not_null" ), CheckConstraint( - f"type NOT IN ('plain_video') OR NOT is_produced OR video_vertical_resolution IS NOT NULL", - name="check_video_vertical_resolution_not_null" + f"type NOT IN ('plain_video', 'thumbnail') OR NOT is_produced OR vertical_resolution IS NOT NULL", + name="check_vertical_resolution_not_null" ), CheckConstraint( - f"type NOT IN ('plain_video') OR NOT is_produced OR video_horizontal_resolution IS NOT NULL", - name="check_video_horizontal_resolution_not_null" + f"type NOT IN ('plain_video', 'thumbnail') OR NOT is_produced OR horizontal_resolution IS NOT NULL", + name="check_horizontal_resolution_not_null" ), CheckConstraint( f"type NOT IN ('plain_video') OR NOT is_produced OR video_frame_rate_numerator IS NOT NULL", @@ -371,13 +372,13 @@ class SingleAudioContainingMedium(ApiObject): class SingleVideoContainingMedium(ApiObject): - video_vertical_resolution: Mapped[int] = api_mapped( + vertical_resolution: Mapped[int] = api_mapped( mapped_column(nullable=True, use_existing_column=True), ApiIntegerField( include_in_data=True ) ) - video_horizontal_resolution: Mapped[int] = api_mapped( + horizontal_resolution: Mapped[int] = api_mapped( mapped_column(nullable=True, use_existing_column=True), ApiIntegerField( include_in_data=True @@ -397,6 +398,22 @@ class SingleVideoContainingMedium(ApiObject): ) +class SingleImageContainingMedium(ApiObject): + + vertical_resolution: Mapped[int] = api_mapped( + mapped_column(nullable=True, use_existing_column=True), + ApiIntegerField( + include_in_data=True + ) + ) + horizontal_resolution: Mapped[int] = api_mapped( + mapped_column(nullable=True, use_existing_column=True), + ApiIntegerField( + include_in_data=True + ) + ) + + class PlainVideoTargetMedium(TargetMedium, FileMedium, SingleVideoContainingMedium, SingleAudioContainingMedium): __tablename__ = None # Prevent our own base from adding a table name. This should be a single-table inheritance __mapper_args__ = { @@ -425,13 +442,21 @@ class PlainAudioTargetMedium(TargetMedium, FileMedium, SingleAudioContainingMedi ) -class ThumbnailTargetMedium(TargetMedium, FileMedium): +# Thumbnail is a different type so that the Frontend knows what to display as the thumbnail +class ThumbnailTargetMedium(TargetMedium, FileMedium, SingleImageContainingMedium): __tablename__ = None # Prevent our own base from adding a table name. This should be a single-table inheritance __mapper_args__ = { "polymorphic_identity": TargetMediumType.THUMBNAIL } +class ImageTargetMedium(TargetMedium, FileMedium, SingleImageContainingMedium): + __tablename__ = None # Prevent our own base from adding a table name. This should be a single-table inheritance + __mapper_args__ = { + "polymorphic_identity": TargetMediumType.IMAGE + } + + class PublishMedium(VisibilityApiObject, DeletableApiObject, Base): __api_data__ = ApiObjectClass( parent_relationship_config_ids=["lecture"]