Skip to content

Commit dc77756

Browse files
Vaghinak BasentsyanVaghinak Basentsyan
authored andcommitted
Added move/copy images error messages
1 parent d9dacbf commit dc77756

File tree

2 files changed

+26
-36
lines changed

2 files changed

+26
-36
lines changed

src/superannotate/lib/core/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
ATTACH_PROJECT_LIMIT_ERROR_MESSAGE = "The number of items you want to attach exceeds the limit of 500 000 items per project."
8383
ATTACH_USER_LIMIT_ERROR_MESSAGE = "The number of items you want to attach exceeds the limit of your subscription plan."
8484

85+
COPY_ITEMS_LIMIT_ERROR_MESSAGE = "The number of items you want to copy exceeds the limit of 50 000 items per folder."
86+
COPY_ITEM_PROJECT_LIMIT_ERROR_MESSAGE = "The copy exceeds the limit of 50 0000 items per project."
87+
MOVE_ITEMS_LIMIT_ERROR_MESSAGE = "The number of items you want to move exceeds the limit of 50 000 items per folder."
88+
MOVE_ITEM_PROJECT_LIMIT_ERROR_MESSAGE = "The number of items you want to move exceeds the limit of 50 000 items per folder."
89+
8590
COPY_FOLDER_LIMIT_ERROR_MESSAGE = (
8691
"The number of items you want to copy exceeds the limit of 50 000 items per folder."
8792
)

src/superannotate/lib/core/usecases/images.py

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -592,15 +592,11 @@ def _validate_limitations(self, images_to_copy_count):
592592
project_id=self._project.uuid,
593593
folder_id=self._to_folder.uuid,
594594
)
595-
errors = []
596595
if not response.ok:
597596
raise AppValidationException(response.error)
598597
if images_to_copy_count > response.data.folder_limit.remaining_image_count:
599-
errors.append(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
600-
elif images_to_copy_count > response.data.project_limit.remaining_image_count:
601-
errors.append(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
602-
if errors:
603-
raise AppValidationException(errors)
598+
AppValidationException(constances.COPY_ITEMS_LIMIT_ERROR_MESSAGE)
599+
604600

605601
def validate_project_type(self):
606602
if self._project.project_type in constances.LIMITED_FUNCTIONS:
@@ -740,7 +736,7 @@ def validate_limitations(self):
740736
if not response.ok:
741737
raise AppValidationException(response.error)
742738
if to_upload_count > response.data.folder_limit.remaining_image_count:
743-
raise AppValidationException(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
739+
raise AppValidationException(constances.MOVE_ITEMS_LIMIT_ERROR_MESSAGE)
744740

745741
def execute(self):
746742
if self.is_valid():
@@ -1135,18 +1131,15 @@ def validate_limitations(self):
11351131
project_id=self._project.uuid,
11361132
folder_id=self._folder.uuid,
11371133
)
1138-
errors = []
11391134
if response.data.folder_limit.remaining_image_count < 1:
1140-
errors.append(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
1135+
raise AppValidationException(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
11411136
elif response.data.project_limit.remaining_image_count < 1:
1142-
errors.append(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
1137+
raise AppValidationException(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
11431138
elif (
11441139
response.data.super_user_limit
11451140
and response.data.super_user_limit.remaining_image_count < 1
11461141
):
1147-
errors.append(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)
1148-
if errors:
1149-
raise AppValidationException("\n".join(errors))
1142+
raise AppValidationException(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)
11501143

11511144
@property
11521145
def auth_data(self):
@@ -1276,18 +1269,15 @@ def validate_limitations(self):
12761269
if not response.ok:
12771270
raise AppValidationException(response.error)
12781271
to_upload_count = len(self.images_to_upload)
1279-
errors = []
12801272
if to_upload_count > response.data.folder_limit.remaining_image_count:
1281-
errors.append(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
1273+
raise AppValidationException(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
12821274
elif to_upload_count > response.data.project_limit.remaining_image_count:
1283-
errors.append(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
1275+
raise AppValidationException(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
12841276
elif (
12851277
response.data.super_user_limit
12861278
and to_upload_count > response.data.super_user_limit.remaining_image_count
12871279
):
1288-
errors.append(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)
1289-
if errors:
1290-
raise AppValidationException("\n".join(errors))
1280+
raise AppValidationException(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)
12911281

12921282
def validate_annotation_status(self):
12931283
if (
@@ -1596,18 +1586,15 @@ def validate_limitations(self):
15961586
if not response.ok:
15971587
raise AppValidationException(response.error)
15981588
to_upload_count = len(self._image_urls)
1599-
errors = []
16001589
if to_upload_count > response.data.folder_limit.remaining_image_count:
1601-
errors.append(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
1590+
raise AppValidationException(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
16021591
elif to_upload_count > response.data.project_limit.remaining_image_count:
1603-
errors.append(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
1592+
raise AppValidationException(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
16041593
elif (
16051594
response.data.super_user_limit
16061595
and to_upload_count > response.data.super_user_limit.remaining_image_count
16071596
):
1608-
errors.append(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)
1609-
if errors:
1610-
raise AppValidationException("\n".join(errors))
1597+
raise AppValidationException(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)
16111598

16121599
def validate_image_names(self):
16131600
if self._image_names and len(self._image_names) != len(self._image_urls):
@@ -1887,18 +1874,15 @@ def validate_limitations(self):
18871874
)
18881875
if not response.ok:
18891876
raise AppValidationException(response.error)
1890-
errors = []
18911877
if attachments_count > response.data.folder_limit.remaining_image_count:
1892-
errors.append(constances.ATTACH_FOLDER_LIMIT_ERROR_MESSAGE)
1878+
raise AppValidationException(constances.ATTACH_FOLDER_LIMIT_ERROR_MESSAGE)
18931879
elif attachments_count > response.data.project_limit.remaining_image_count:
1894-
errors.append(constances.ATTACH_PROJECT_LIMIT_ERROR_MESSAGE)
1880+
raise AppValidationException(constances.ATTACH_PROJECT_LIMIT_ERROR_MESSAGE)
18951881
elif (
18961882
response.data.super_user_limit
18971883
and attachments_count > response.data.super_user_limit.remaining_image_count
18981884
):
1899-
errors.append(constances.ATTACH_USER_LIMIT_ERROR_MESSAGE)
1900-
if errors:
1901-
raise AppValidationException("\n".join(errors))
1885+
raise AppValidationException(constances.ATTACH_USER_LIMIT_ERROR_MESSAGE)
19021886

19031887
@property
19041888
def annotation_status_code(self):
@@ -1988,13 +1972,14 @@ def validate_limitations(self):
19881972
)
19891973
if not response.ok:
19901974
raise AppValidationException(response.error)
1991-
errors = []
19921975
if response.data.folder_limit.remaining_image_count < 1:
1993-
errors.append(constances.ATTACH_FOLDER_LIMIT_ERROR_MESSAGE)
1976+
if self._move:
1977+
raise AppValidationException(constances.MOVE_ITEMS_LIMIT_ERROR_MESSAGE)
1978+
raise AppValidationException(constances.COPY_ITEMS_LIMIT_ERROR_MESSAGE)
19941979
elif self._to_project.uuid != self._from_project.uuid and response.data.project_limit.remaining_image_count < 1:
1995-
errors.append(constances.ATTACH_PROJECT_LIMIT_ERROR_MESSAGE)
1996-
if errors:
1997-
raise AppValidationException("\n".join(errors))
1980+
if self._move:
1981+
raise AppValidationException(constances.MOVE_ITEM_PROJECT_LIMIT_ERROR_MESSAGE)
1982+
raise AppValidationException(constances.COPY_ITEM_PROJECT_LIMIT_ERROR_MESSAGE)
19981983

19991984
def execute(self) -> Response:
20001985
if self.is_valid():

0 commit comments

Comments
 (0)