Skip to content

Commit fe3ebcc

Browse files
committed
changed project/settings serializers
1 parent 0e7687f commit fe3ebcc

23 files changed

+260
-275
lines changed

src/superannotate/lib/app/interface/cli_interface.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,7 @@ def _upload_annotations(
195195
output_dir=temp_dir,
196196
dataset_format=format,
197197
dataset_name=dataset_name,
198-
project_type=constances.ProjectType.get_name(
199-
project["project"].type
200-
),
198+
project_type=project.type.name,
201199
task=task,
202200
)
203201
annotations_path = temp_dir

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 35 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,7 @@ def search_projects(
162162
if return_metadata:
163163
return [
164164
ProjectSerializer(project).serialize(
165-
exclude={
166-
"annotation_classes",
167-
"workflows",
168-
"settings",
169-
"contributors",
170-
"classes",
171-
}
165+
exclude={"settings", "workflows", "contributors", "classes"}
172166
)
173167
for project in result
174168
]
@@ -434,16 +428,14 @@ def copy_image(
434428
destination_project
435429
).data
436430

437-
if destination_project_metadata["project"].type in [
431+
if destination_project_metadata.type.value in [
438432
constants.ProjectType.VIDEO.value,
439433
constants.ProjectType.DOCUMENT.value,
440-
] or source_project_metadata["project"].type in [
434+
] or source_project_metadata.type.value in [
441435
constants.ProjectType.VIDEO.value,
442436
constants.ProjectType.DOCUMENT.value,
443437
]:
444-
raise AppException(
445-
LIMITED_FUNCTIONS[source_project_metadata["project"].type]
446-
)
438+
raise AppException(LIMITED_FUNCTIONS[source_project_metadata.type])
447439

448440
response = self.controller.copy_image(
449441
from_project_name=source_project_name,
@@ -521,16 +513,7 @@ def get_project_metadata(
521513
if response.errors:
522514
raise AppException(response.errors)
523515

524-
return response.data.dict()
525-
# metadata = ProjectSerializer(response["project"]).serialize()
526-
#
527-
# for elem in "classes", "workflows", "contributors":
528-
# if response.get(elem):
529-
# metadata[elem] = [
530-
# BaseSerializer(attribute).serialize()
531-
# for attribute in response[elem]
532-
# ]
533-
# return metadata
516+
return ProjectSerializer(response.data).serialize()
534517

535518
def get_project_settings(self, project: Union[NotEmptyStr, dict]):
536519
"""Gets project's settings.
@@ -546,7 +529,8 @@ def get_project_settings(self, project: Union[NotEmptyStr, dict]):
546529
project_name, folder_name = extract_project_folder(project)
547530
settings = self.controller.get_project_settings(project_name=project_name)
548531
settings = [
549-
SettingsSerializer(attribute).serialize() for attribute in settings.data
532+
SettingsSerializer(attribute.dict()).serialize()
533+
for attribute in settings.data
550534
]
551535
return settings
552536

@@ -587,7 +571,10 @@ def search_annotation_classes(
587571
)
588572
if response.errors:
589573
raise AppException(response.errors)
590-
return [BaseSerializer(i).serialize(exclude_unset=True) for i in response.data]
574+
return [
575+
i.dict(exclude={"attribute_groups": {"__all__": {"is_multiselect"}}})
576+
for i in response.data
577+
]
591578

592579
def set_project_default_image_quality_in_editor(
593580
self,
@@ -1519,11 +1506,11 @@ def upload_preannotations_from_folder_to_project(
15191506
project_name, folder_name = extract_project_folder(project)
15201507
project_folder_name = project_name + (f"/{folder_name}" if folder_name else "")
15211508
project = self.controller.get_project_metadata(project_name).data
1522-
if project["project"].type in [
1523-
constants.ProjectType.VIDEO.value,
1524-
constants.ProjectType.DOCUMENT.value,
1509+
if project.type in [
1510+
constants.ProjectType.VIDEO,
1511+
constants.ProjectType.DOCUMENT,
15251512
]:
1526-
raise AppException(LIMITED_FUNCTIONS[project["project"].type])
1513+
raise AppException(LIMITED_FUNCTIONS[project.type])
15271514
if recursive_subfolders:
15281515
logger.info(
15291516
"When using recursive subfolder parsing same name annotations in different "
@@ -1582,11 +1569,11 @@ def upload_image_annotations(
15821569
project_name, folder_name = extract_project_folder(project)
15831570

15841571
project = self.controller.get_project_metadata(project_name).data
1585-
if project["project"].type in [
1586-
constants.ProjectType.VIDEO.value,
1587-
constants.ProjectType.DOCUMENT.value,
1572+
if project.type in [
1573+
constants.ProjectType.VIDEO,
1574+
constants.ProjectType.DOCUMENT,
15881575
]:
1589-
raise AppException(LIMITED_FUNCTIONS[project["project"].type])
1576+
raise AppException(LIMITED_FUNCTIONS[project.type])
15901577

15911578
if not mask:
15921579
if not isinstance(annotation_json, dict):
@@ -1668,11 +1655,11 @@ def benchmark(
16681655
project_name = project["name"]
16691656

16701657
project = self.controller.get_project_metadata(project_name).data
1671-
if project["project"].type in [
1672-
constants.ProjectType.VIDEO.value,
1673-
constants.ProjectType.DOCUMENT.value,
1658+
if project.type in [
1659+
constants.ProjectType.VIDEO,
1660+
constants.ProjectType.DOCUMENT,
16741661
]:
1675-
raise AppException(LIMITED_FUNCTIONS[project["project"].type])
1662+
raise AppException(LIMITED_FUNCTIONS[project.type])
16761663

16771664
if not export_root:
16781665
with tempfile.TemporaryDirectory() as temp_dir:
@@ -1820,11 +1807,11 @@ def add_annotation_bbox_to_image(
18201807
"""
18211808
project_name, folder_name = extract_project_folder(project)
18221809
project = self.controller.get_project_metadata(project_name).data
1823-
if project["project"].type in [
1824-
constants.ProjectType.VIDEO.value,
1825-
constants.ProjectType.DOCUMENT.value,
1810+
if project.type in [
1811+
constants.ProjectType.VIDEO,
1812+
constants.ProjectType.DOCUMENT,
18261813
]:
1827-
raise AppException(LIMITED_FUNCTIONS[project["project"].type])
1814+
raise AppException(LIMITED_FUNCTIONS[project.type])
18281815
response = self.controller.get_annotations(
18291816
project_name=project_name,
18301817
folder_name=folder_name,
@@ -1878,11 +1865,11 @@ def add_annotation_point_to_image(
18781865
"""
18791866
project_name, folder_name = extract_project_folder(project)
18801867
project = self.controller.get_project_metadata(project_name).data
1881-
if project["project"].type in [
1882-
constants.ProjectType.VIDEO.value,
1883-
constants.ProjectType.DOCUMENT.value,
1868+
if project.type in [
1869+
constants.ProjectType.VIDEO,
1870+
constants.ProjectType.DOCUMENT,
18841871
]:
1885-
raise AppException(LIMITED_FUNCTIONS[project["project"].type])
1872+
raise AppException(LIMITED_FUNCTIONS[project.type])
18861873
response = self.controller.get_annotations(
18871874
project_name=project_name,
18881875
folder_name=folder_name,
@@ -1934,11 +1921,11 @@ def add_annotation_comment_to_image(
19341921
"""
19351922
project_name, folder_name = extract_project_folder(project)
19361923
project = self.controller.get_project_metadata(project_name).data
1937-
if project["project"].type in [
1938-
constants.ProjectType.VIDEO.value,
1939-
constants.ProjectType.DOCUMENT.value,
1924+
if project.type in [
1925+
constants.ProjectType.VIDEO,
1926+
constants.ProjectType.DOCUMENT,
19401927
]:
1941-
raise AppException(LIMITED_FUNCTIONS[project["project"].type])
1928+
raise AppException(LIMITED_FUNCTIONS[project.type])
19421929
response = self.controller.get_annotations(
19431930
project_name=project_name,
19441931
folder_name=folder_name,

src/superannotate/lib/app/serializers.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class ProjectSerializer(BaseSerializer):
118118
def serialize(
119119
self,
120120
fields: List[str] = None,
121-
by_alias: bool = False,
121+
by_alias: bool = True,
122122
flat: bool = False,
123123
exclude: Set[str] = None,
124124
):
@@ -130,11 +130,9 @@ def serialize(
130130
data["settings"] = [
131131
SettingsSerializer(setting).serialize() for setting in data["settings"]
132132
]
133-
data["type"] = constance.ProjectType.get_name(data["type"])
134-
if data.get("status"):
135-
data["status"] = constance.ProjectStatus.get_name(data["status"])
136-
else:
133+
if not data.get("status"):
137134
data["status"] = "Undefined"
135+
138136
if data.get("upload_state"):
139137
data["upload_state"] = constance.UploadState(data["upload_state"]).name
140138
if data.get("users"):
@@ -152,18 +150,14 @@ def serialize(self):
152150
return data
153151

154152

155-
class SettingsSerializer(BaseSerializer):
156-
def serialize(
157-
self,
158-
fields: List[str] = None,
159-
by_alias: bool = True,
160-
flat: bool = False,
161-
exclude=None,
162-
):
163-
data = super().serialize(fields, by_alias, flat, exclude)
164-
if data["attribute"] == "ImageQuality":
165-
data["value"] = constance.ImageQuality.get_name(data["value"])
166-
return data
153+
class SettingsSerializer:
154+
def __init__(self, data: dict):
155+
self.data = data
156+
157+
def serialize(self):
158+
if self.data["attribute"] == "ImageQuality":
159+
self.data["value"] = constance.ImageQuality.get_name(self.data["value"])
160+
return self.data
167161

168162

169163
class EntitySerializer:

src/superannotate/lib/core/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@
7979
)
8080

8181
LIMITED_FUNCTIONS = {
82-
ProjectType.VIDEO.value: DEPRECATED_VIDEO_PROJECTS_MESSAGE,
83-
ProjectType.DOCUMENT.value: DEPRECATED_DOCUMENT_PROJECTS_MESSAGE,
82+
ProjectType.VIDEO: DEPRECATED_VIDEO_PROJECTS_MESSAGE,
83+
ProjectType.DOCUMENT: DEPRECATED_DOCUMENT_PROJECTS_MESSAGE,
8484
}
8585

8686
METADATA_DEPRICATED_FOR_PIXEL = (

src/superannotate/lib/core/entities/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from lib.core.entities.base import BaseItemEntity
22
from lib.core.entities.base import SubSetEntity
3-
from lib.core.entities.project import AttachmentEntity
4-
from lib.core.entities.project import ProjectEntity
5-
from lib.core.entities.project import SettingEntity
63
from lib.core.entities.classes import AnnotationClassEntity
74
from lib.core.entities.integrations import IntegrationEntity
85
from lib.core.entities.items import DocumentEntity
96
from lib.core.entities.items import TmpImageEntity
107
from lib.core.entities.items import VideoEntity
8+
from lib.core.entities.project import AttachmentEntity
9+
from lib.core.entities.project import ProjectEntity
10+
from lib.core.entities.project import SettingEntity
1111
from lib.core.entities.project_entities import BaseEntity
1212
from lib.core.entities.project_entities import ConfigEntity
1313
from lib.core.entities.project_entities import FolderEntity
@@ -44,5 +44,5 @@
4444
"UserEntity",
4545
"TeamEntity",
4646
"MLModelEntity",
47-
"IntegrationEntity"
47+
"IntegrationEntity",
4848
]

0 commit comments

Comments
 (0)