mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 12:54:40 +01:00
Apply suggestions from code review
Co-authored-by: Robin De Lillo <robin@ynput.io> Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
This commit is contained in:
parent
bc911f4dbc
commit
93b59710b2
2 changed files with 17 additions and 17 deletions
|
|
@ -50,21 +50,21 @@ class CollectExplicitResolution(
|
|||
dict: dictionary with width, height and pixel_aspect
|
||||
"""
|
||||
resolution_items = self._get_resolution_items()
|
||||
item_values = None
|
||||
# check if resolution_value is in cached items
|
||||
if resolution_value in resolution_items:
|
||||
item_values = resolution_items[resolution_value]
|
||||
# ensure resolution_value is part of expected items
|
||||
item_values = resolution_items.get(resolution_value)
|
||||
|
||||
# if the item is in the cache, get the values from it
|
||||
if item_values:
|
||||
# if the item is in the cache, get the values from it
|
||||
return {
|
||||
"resolutionWidth": item_values["width"],
|
||||
"resolutionHeight": item_values["height"],
|
||||
"pixelAspect": item_values["pixel_aspect"],
|
||||
}
|
||||
else:
|
||||
raise PublishError(
|
||||
f"Invalid resolution value: {resolution_value}")
|
||||
|
||||
raise PublishError(
|
||||
f"Invalid resolution value: {resolution_value} "
|
||||
f"expected choices: {resolution_items}"
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _get_resolution_items(cls):
|
||||
|
|
@ -72,7 +72,7 @@ class CollectExplicitResolution(
|
|||
resolution_items = {}
|
||||
for item in cls.options:
|
||||
item_text = (
|
||||
f"{item['width']}x{item['height']}x{item['pixel_aspect']}")
|
||||
f"{item['width']}x{item['height']} ({item['pixel_aspect']})")
|
||||
resolution_items[item_text] = item
|
||||
|
||||
cls.resolution_items = resolution_items
|
||||
|
|
|
|||
|
|
@ -191,21 +191,21 @@ class ResolutionOptionsModel(BaseSettingsModel):
|
|||
|
||||
|
||||
def ensure_unique_resolution_option(
|
||||
objects: Iterable[Any], field_name: str | None = None) -> None: # noqa: C901
|
||||
objects: list[Any], field_name: str | None = None) -> None: # noqa: C901
|
||||
"""Ensure a list of objects have unique option attributes.
|
||||
|
||||
This function checks if the list of objects has unique 'width',
|
||||
'height' and 'pixel_aspect' properties.
|
||||
"""
|
||||
options = []
|
||||
options = set()
|
||||
for obj in objects:
|
||||
item_test_text = f"{obj.width}x{obj.height}x{obj.pixel_aspect}"
|
||||
if item_test_text not in options:
|
||||
options.append(item_test_text)
|
||||
else:
|
||||
if item_test_text in options:
|
||||
raise BadRequestException(
|
||||
f"Duplicate option '{item_test_text}'")
|
||||
|
||||
options.add(item_test_text)
|
||||
|
||||
|
||||
class CollectExplicitResolutionModel(BaseSettingsModel):
|
||||
enabled: bool = SettingsField(True, title="Enabled")
|
||||
|
|
@ -218,14 +218,14 @@ class CollectExplicitResolutionModel(BaseSettingsModel):
|
|||
)
|
||||
options: list[ResolutionOptionsModel] = SettingsField(
|
||||
default_factory=list,
|
||||
title="Resolution options",
|
||||
title="Resolution choices",
|
||||
description=(
|
||||
"Options to be provided in publisher attribute"
|
||||
"Available resolution choices to be displayed in the publishers attribute."
|
||||
)
|
||||
)
|
||||
|
||||
@validator("options")
|
||||
def validate_unique_options(cls, value):
|
||||
def validate_unique_resolution_options(cls, value):
|
||||
ensure_unique_resolution_option(value)
|
||||
return value
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue