Skip to content

Commit de7e5cb

Browse files
committed
Add default attribute values in workflow
1 parent 19c9f4e commit de7e5cb

File tree

3 files changed

+117
-33
lines changed

3 files changed

+117
-33
lines changed

superannotate/db/projects.py

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,15 +1875,12 @@ def get_project_workflow(project):
18751875
def set_project_workflow(project, new_workflow):
18761876
"""Sets project's workflow.
18771877
1878-
new_workflow example: [{ "step" : <step_num>, "className" : <annotation_class>, "tool" : <tool_num>, ...},...]
1878+
new_workflow example: [{ "step" : <step_num>, "className" : <annotation_class>, "tool" : <tool_num>, "attribute":[{"name" : <attribute_value>, "attribute_group" : {"name": <attribute_group>}},...]},...]
18791879
18801880
:param project: project name or metadata
18811881
:type project: str or dict
18821882
:param project: new workflow list of dicts
18831883
:type project: list of dicts
1884-
1885-
:return: updated part of project's workflow
1886-
:rtype: list of dicts
18871884
"""
18881885
if not isinstance(project, dict):
18891886
project = get_project_metadata_bare(project)
@@ -1902,33 +1899,68 @@ def set_project_workflow(project, new_workflow):
19021899
for step in new_list:
19031900
if "id" in step:
19041901
del step["id"]
1905-
if "className" in step:
1906-
found = False
1907-
for an_class in annotation_classes:
1908-
if an_class["name"] == step["className"]:
1909-
step["class_id"] = an_class["id"]
1910-
del step["className"]
1911-
found = True
1902+
if "className" not in step:
1903+
continue
1904+
for an_class in annotation_classes:
1905+
if an_class["name"] == step["className"]:
1906+
step["class_id"] = an_class["id"]
1907+
break
1908+
else:
1909+
raise SABaseException(
1910+
0, "Annotation class not found in set_project_workflow."
1911+
)
1912+
json_req = {"steps": [step]}
1913+
response = _api.send_request(
1914+
req_type='POST',
1915+
path=f'/project/{project_id}/workflow',
1916+
params=params,
1917+
json_req=json_req
1918+
)
1919+
if not response.ok:
1920+
raise SABaseException(
1921+
response.status_code,
1922+
"Couldn't set project workflow " + response.text
1923+
)
1924+
workflow_id = response.json()[0]["id"]
1925+
if "attribute" not in step:
1926+
continue
1927+
request_data = []
1928+
for attribute in step["attribute"]:
1929+
for att_class in an_class["attribute_groups"]:
1930+
if att_class["name"] == attribute["attribute"]["attribute_group"
1931+
]["name"]:
19121932
break
1913-
if not found:
1933+
else:
1934+
raise SABaseException(
1935+
0, "Attribute group not found in set_project_workflow."
1936+
)
1937+
for att_value in att_class["attributes"]:
1938+
if att_value["name"] == attribute["attribute"]["name"]:
1939+
attribute_id = att_value["id"]
1940+
break
1941+
else:
19141942
raise SABaseException(
1915-
0, "Annotation class not found in set_project_workflow."
1943+
0, "Attribute value not found in set_project_workflow."
19161944
)
19171945

1918-
json_req = {"steps": new_list}
1919-
response = _api.send_request(
1920-
req_type='POST',
1921-
path=f'/project/{project_id}/workflow',
1922-
params=params,
1923-
json_req=json_req
1924-
)
1925-
if not response.ok:
1926-
raise SABaseException(
1927-
response.status_code,
1928-
"Couldn't set project workflow " + response.text
1946+
request_data.append(
1947+
{
1948+
"workflow_id": workflow_id,
1949+
"attribute_id": attribute_id
1950+
}
1951+
)
1952+
1953+
response = _api.send_request(
1954+
req_type='POST',
1955+
path=f'/project/{project_id}/workflow_attribute',
1956+
params=params,
1957+
json_req={"data": request_data}
19291958
)
1930-
res = response.json()
1931-
return res
1959+
if not response.ok:
1960+
raise SABaseException(
1961+
response.status_code,
1962+
"Couldn't set project workflow " + response.text
1963+
)
19321964

19331965

19341966
def get_project_settings(project):

superannotate/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.2.2"
1+
__version__ = "3.2.3"

tests/test_clone_project.py

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,27 @@ def test_create_like_project(tmpdir):
1515
sa.delete_project(project)
1616

1717
sa.create_project(PROJECT_NAME, "tt", "Vector")
18-
sa.create_annotation_class(PROJECT_NAME, "rrr", "#FFAAFF")
18+
sa.create_annotation_class(
19+
PROJECT_NAME, "rrr", "#FFAAFF", [
20+
{
21+
"name": "tall",
22+
"is_multiselect": 0,
23+
"attributes": [{
24+
"name": "yes"
25+
}, {
26+
"name": "no"
27+
}]
28+
}, {
29+
"name": "age",
30+
"is_multiselect": 0,
31+
"attributes": [{
32+
"name": "young"
33+
}, {
34+
"name": "old"
35+
}]
36+
}
37+
]
38+
)
1939

2040
old_settings = sa.get_project_settings(PROJECT_NAME)
2141
for setting in old_settings:
@@ -29,11 +49,36 @@ def test_create_like_project(tmpdir):
2949
}]
3050
)
3151
sa.set_project_workflow(
32-
PROJECT_NAME, [{
33-
"step": 1,
34-
"className": "rrr",
35-
"tool": 3
36-
}]
52+
PROJECT_NAME, [
53+
{
54+
"step":
55+
1,
56+
"className":
57+
"rrr",
58+
"tool":
59+
3,
60+
"attribute":
61+
[
62+
{
63+
"attribute":
64+
{
65+
"name": "young",
66+
"attribute_group": {
67+
"name": "age"
68+
}
69+
}
70+
}, {
71+
"attribute":
72+
{
73+
"name": "yes",
74+
"attribute_group": {
75+
"name": "tall"
76+
}
77+
}
78+
}
79+
]
80+
}
81+
]
3782
)
3883
users = sa.search_team_contributors()
3984
sa.share_project(PROJECT_NAME, users[1], "QA")
@@ -65,6 +110,13 @@ def test_create_like_project(tmpdir):
65110
assert len(new_workflow) == 1
66111
assert new_workflow[0]["className"] == "rrr"
67112
assert new_workflow[0]["tool"] == 3
113+
assert len(new_workflow[0]["attribute"]) == 2
114+
assert new_workflow[0]["attribute"][0]["attribute"]["name"] == "young"
115+
assert new_workflow[0]["attribute"][0]["attribute"]["attribute_group"][
116+
"name"] == "age"
117+
assert new_workflow[0]["attribute"][1]["attribute"]["name"] == "yes"
118+
assert new_workflow[0]["attribute"][1]["attribute"]["attribute_group"][
119+
"name"] == "tall"
68120

69121
new_project = sa.get_project_metadata(
70122
new_project["name"], include_contributors=True

0 commit comments

Comments
 (0)