Skip to content

Commit

Permalink
Merge pull request #736 from EvanBldy/master
Browse files Browse the repository at this point in the history
Add routes / models to manage preview background files
  • Loading branch information
EvanBldy authored Nov 13, 2023
2 parents a26b098 + 831489a commit 00e89f9
Show file tree
Hide file tree
Showing 19 changed files with 1,019 additions and 79 deletions.
8 changes: 5 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ install_requires =
ldap3==2.9.1
matterhook==0.2
meilisearch==0.28.4
numpy==1.24.4
opencv-python==4.8.1.78
OpenTimelineIO==0.15.0
orjson==3.9.10
pillow==10.1.0
Expand All @@ -70,7 +72,7 @@ install_requires =
rq==1.15.1
slackclient==2.9.4
sqlalchemy_utils==0.41.1
sqlalchemy==2.0.22
sqlalchemy==2.0.23
ua-parser==0.18.0
werkzeug==3.0.1

Expand Down Expand Up @@ -98,10 +100,10 @@ test =
monitoring =
prometheus-flask-exporter==0.23.0
pygelf==0.4.2
sentry-sdk==1.33.1
sentry-sdk==1.35.0

lint =
black==23.10.1
black==23.11.0
pre-commit==3.5.0

[options.entry_points]
Expand Down
10 changes: 9 additions & 1 deletion zou/app/blueprints/crud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@
WorkingFilesResource,
WorkingFileResource,
)

from zou.app.blueprints.crud.preview_background_file import (
PreviewBackgroundFileResource,
PreviewBackgroundFilesResource,
)

routes = [
("/data/persons", PersonsResource),
Expand Down Expand Up @@ -190,6 +193,11 @@
("/data/subscriptions/<instance_id>", SubscriptionResource),
("/data/entity-links/", EntityLinksResource),
("/data/entity-links/<instance_id>", EntityLinkResource),
("/data/preview-background-files", PreviewBackgroundFilesResource),
(
"/data/preview-background-files/<instance_id>",
PreviewBackgroundFileResource,
),
]

blueprint = Blueprint("/data", "data")
Expand Down
61 changes: 61 additions & 0 deletions zou/app/blueprints/crud/preview_background_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from zou.app.models.preview_background_file import PreviewBackgroundFile
from zou.app.services.exception import ArgumentsException
from zou.app.services import files_service, deletion_service

from zou.app.blueprints.crud.base import BaseModelResource, BaseModelsResource


class PreviewBackgroundFilesResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, PreviewBackgroundFile)

def check_read_permissions(self):
return True

def update_data(self, data):
name = data.get("name", None)
preview_background_file = PreviewBackgroundFile.get_by(name=name)
if preview_background_file is not None:
raise ArgumentsException(
"A preview background file with similar name already exists"
)
return data

def post_creation(self, instance):
if instance.is_default:
files_service.reset_default_preview_background_files(instance.id)
files_service.clear_preview_background_file_cache(str(instance.id))
return instance.serialize()


class PreviewBackgroundFileResource(BaseModelResource):
def __init__(self):
BaseModelResource.__init__(self, PreviewBackgroundFile)

def check_read_permissions(self, instance):
return True

def update_data(self, data, instance_id):
name = data.get("name", None)
if name is not None:
preview_background_file = PreviewBackgroundFile.get_by(name=name)
if preview_background_file is not None and instance_id != str(
preview_background_file.id
):
raise ArgumentsException(
"A preview background file with similar name already exists"
)
return data

def post_update(self, instance_dict):
if instance_dict["is_default"]:
files_service.reset_default_preview_background_files(
instance_dict["id"]
)
files_service.clear_preview_background_file_cache(instance_dict["id"])
return instance_dict

def post_delete(self, instance_dict):
deletion_service.clear_preview_background_files(instance_dict["id"])
files_service.clear_preview_background_file_cache(instance_dict["id"])
return instance_dict
57 changes: 57 additions & 0 deletions zou/app/blueprints/crud/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
assets_service,
tasks_service,
status_automations_service,
files_service,
)
from zou.app.utils import events, permissions, fields

Expand Down Expand Up @@ -79,6 +80,31 @@ def update_data(self, data):
)
for task_type_id in data["status_automations"]
]

if "preview_background_files" in data:
data["preview_background_files"] = [
files_service.get_preview_background_file_raw(
preview_background_file_id
)
for preview_background_file_id in data[
"preview_background_files"
]
]

if data.get("preview_background_file_id") is not None:
preview_background_files_ids = []
if "preview_background_files" in data:
preview_background_files_ids = [
str(preview_background_file.id)
for preview_background_file in data[
"preview_background_files"
]
]
if (
data["preview_background_file_id"]
not in preview_background_files_ids
):
raise ArgumentsException("Invalid preview_background_file_id")
return data

def post_creation(self, project):
Expand Down Expand Up @@ -132,6 +158,37 @@ def pre_update(self, project_dict, data):
)
for task_type_id in data["status_automations"]
]
if "preview_background_files" in data:
data["preview_background_files"] = [
files_service.get_preview_background_file_raw(
preview_background_file_id
)
for preview_background_file_id in data[
"preview_background_files"
]
]

if data.get("preview_background_file_id") is not None:
if "preview_background_files" in data:
preview_background_files_ids = [
str(preview_background_file.id)
for preview_background_file in data[
"preview_background_files"
]
]
else:
preview_background_files_ids = [
preview_background_file_id
for preview_background_file_id in project_dict[
"preview_background_files"
]
]
if (
data["preview_background_file_id"]
not in preview_background_files_ids
):
raise ArgumentsException("Invalid preview_background_file_id")

return data

def post_update(self, project_dict):
Expand Down
15 changes: 15 additions & 0 deletions zou/app/blueprints/previews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
UpdatePreviewPositionResource,
ExtractFrameFromPreview,
ExtractTileFromPreview,
CreatePreviewBackgroundFileResource,
PreviewBackgroundFileThumbnailResource,
PreviewBackgroundFileResource,
)

routes = [
Expand Down Expand Up @@ -98,6 +101,18 @@
"/pictures/thumbnails/projects/<instance_id>.png",
ProjectThumbnailResource,
),
(
"/pictures/preview-background-files/<instance_id>",
CreatePreviewBackgroundFileResource,
),
(
"/pictures/thumbnails/preview-background-files/<instance_id>.png",
PreviewBackgroundFileThumbnailResource,
),
(
"/pictures/preview-background-files/<instance_id>.<extension>",
PreviewBackgroundFileResource,
),
(
"/actions/entities/<entity_id>/set-main-preview/<preview_file_id>",
LegacySetMainPreviewResource,
Expand Down
Loading

0 comments on commit 00e89f9

Please sign in to comment.