Skip to content

Commit

Permalink
Add tasks for measures when creating an algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
uittenbroekrobbert committed Jan 22, 2025
1 parent 9b2dd45 commit 0787177
Show file tree
Hide file tree
Showing 66 changed files with 769 additions and 286 deletions.
16 changes: 16 additions & 0 deletions amt/api/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ def instance(obj: Class, type_string: str) -> bool:
raise TypeError("Unsupported type: " + type_string)


def hasattr_jinja(obj: object, attributes: str) -> bool:
"""
Convenience method that checks whether an object has the given attributes.
:param obj: the object to check
:param attributes: the attributes, seperated by dots, like field1.field2.field3
:return: True if the object has the given attribute and its value is not None, False otherwise
"""
for attribute in attributes.split("."):
if hasattr(obj, attribute) and getattr(obj, attribute) is not None:
obj = getattr(obj, attribute)
else:
return False
return True


templates = LocaleJinja2Templates(
directory="amt/site/templates/", context_processors=[custom_context_processor], undefined=get_undefined_behaviour()
)
Expand All @@ -153,5 +168,6 @@ def instance(obj: Class, type_string: str) -> bool:
templates.env.globals.update(is_editable_resource=is_editable_resource) # pyright: ignore [reportUnknownMemberType]
templates.env.globals.update(replace_digits_in_brackets=replace_digits_in_brackets) # pyright: ignore [reportUnknownMemberType]
templates.env.globals.update(permission=permission) # pyright: ignore [reportUnknownMemberType]
templates.env.globals.update(hasattr=hasattr_jinja) # pyright: ignore [reportUnknownMemberType]
templates.env.tests["permission"] = permission # pyright: ignore [reportUnknownMemberType]
templates.env.add_extension("jinja2_base64_filters.Base64Filters") # pyright: ignore [reportUnknownMemberType]
208 changes: 141 additions & 67 deletions amt/api/routes/algorithm.py

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions amt/api/routes/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
)
from amt.api.routes.shared import get_filters_and_sort_by
from amt.core.authorization import AuthorizationResource, AuthorizationVerb, get_user
from amt.core.exceptions import AMTAuthorizationError
from amt.core.internationalization import get_current_translation
from amt.models import Algorithm
from amt.schema.algorithm import AlgorithmNew
Expand Down Expand Up @@ -172,8 +171,6 @@ async def post_new(
) -> HTMLResponse:
user: dict[str, Any] | None = get_user(request)
# TODO (Robbert): we need to handle (show) repository or service errors in the forms
if user:
algorithm = await algorithms_service.create(algorithm_new, user["sub"])
response = templates.Redirect(request, f"/algorithm/{algorithm.id}/details")
return response
raise AMTAuthorizationError
algorithm = await algorithms_service.create(algorithm_new, user["sub"]) # pyright: ignore[reportOptionalSubscript, reportUnknownArgumentType]
response = templates.Redirect(request, f"/algorithm/{algorithm.id}/details")
return response
18 changes: 8 additions & 10 deletions amt/api/routes/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,19 @@ def replace_none_with_empty_string_inplace(obj: dict[Any, Any] | list[Any] | Ite
"""
if isinstance(obj, list):
for i, item in enumerate(obj):
if item is None and isinstance(item, str):
if item is None:
obj[i] = ""
elif isinstance(item, list | dict | IterMixin):
else:
replace_none_with_empty_string_inplace(item) # pyright: ignore[reportUnknownArgumentType]

elif isinstance(obj, dict):
for key, value in obj.items():
if value is None and isinstance(value, str):
if value is None:
obj[key] = ""
elif isinstance(value, (list, dict, IterMixin)): # noqa: UP038
replace_none_with_empty_string_inplace(value) # pyright: ignore[reportUnknownArgumentType]

else:
replace_none_with_empty_string_inplace(obj[key]) # pyright: ignore[reportUnknownArgumentType]
elif isinstance(obj, IterMixin):
for item in obj:
if isinstance(item, tuple) and item[1] is None:
if getattr(obj, item[0]) is None:
setattr(obj, item[0], "")
if isinstance(item, list | dict | IterMixin):
replace_none_with_empty_string_inplace(item) # pyright: ignore[reportUnknownArgumentType]
else:
replace_none_with_empty_string_inplace(getattr(obj, item[0])) # pyright: ignore[reportUnknownArgumentType]
8 changes: 0 additions & 8 deletions amt/enums/status.py

This file was deleted.

28 changes: 28 additions & 0 deletions amt/enums/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from enum import IntEnum, StrEnum

from amt.api.forms.measure import MeasureStatusOptions


class Status(IntEnum):
TODO = 1
IN_PROGRESS = 2
IN_REVIEW = 3
DONE = 4
NOT_IMPLEMENTED = 5


class TaskType(StrEnum):
MEASURE = "measure"


status_mapper: dict[Status, MeasureStatusOptions] = {
Status.TODO: MeasureStatusOptions.TODO,
Status.IN_PROGRESS: MeasureStatusOptions.IN_PROGRESS,
Status.IN_REVIEW: MeasureStatusOptions.IN_REVIEW,
Status.DONE: MeasureStatusOptions.DONE,
Status.NOT_IMPLEMENTED: MeasureStatusOptions.NOT_IMPLEMENTED,
}


def measure_state_to_status(state: str) -> Status:
return next((k for k, v in status_mapper.items() if v.value == state), Status.TODO)
41 changes: 22 additions & 19 deletions amt/locale/base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ msgstr ""
msgid "Compliance"
msgstr ""

#: amt/api/organization_filter_options.py:16
#: amt/api/organization_filter_options.py:17
msgid "All organizations"
msgstr ""

#: amt/api/organization_filter_options.py:17
msgid "My organizations"
msgstr ""

Expand Down Expand Up @@ -361,14 +365,14 @@ msgstr ""

#: amt/site/templates/algorithms/details_base.html.j2:28
#: amt/site/templates/algorithms/new.html.j2:153
#: amt/site/templates/macros/form_macros.html.j2:168
#: amt/site/templates/macros/form_macros.html.j2:170
#: amt/site/templates/organizations/members.html.j2:33
msgid "Yes"
msgstr ""

#: amt/site/templates/algorithms/details_base.html.j2:31
#: amt/site/templates/algorithms/new.html.j2:163
#: amt/site/templates/macros/form_macros.html.j2:173
#: amt/site/templates/macros/form_macros.html.j2:175
#: amt/site/templates/organizations/members.html.j2:36
msgid "No"
msgstr ""
Expand All @@ -384,6 +388,7 @@ msgstr ""
#: amt/site/templates/algorithms/details_compliance.html.j2:69
#: amt/site/templates/macros/editable.html.j2:28
#: amt/site/templates/macros/editable.html.j2:33
#: amt/site/templates/macros/tasks.html.j2:81
msgid "Edit"
msgstr ""

Expand All @@ -393,15 +398,17 @@ msgstr ""

#: amt/site/templates/algorithms/details_info.html.j2:20
#: amt/site/templates/algorithms/details_info.html.j2:48
#: amt/site/templates/macros/tasks.html.j2:32
#: amt/site/templates/macros/tasks.html.j2:33
msgid "Done"
msgstr ""

#: amt/site/templates/algorithms/details_info.html.j2:44
#: amt/site/templates/macros/tasks.html.j2:12
msgid "To do"
msgstr ""

#: amt/site/templates/algorithms/details_info.html.j2:46
#: amt/site/templates/macros/tasks.html.j2:19
msgid "In progress"
msgstr ""

Expand Down Expand Up @@ -609,47 +616,43 @@ msgstr ""
msgid "Algorithmic Management Toolkit (AMT)"
msgstr ""

#: amt/site/templates/macros/form_macros.html.j2:58
#: amt/site/templates/macros/form_macros.html.j2:60
msgid "Are you sure you want to remove "
msgstr ""

#: amt/site/templates/macros/form_macros.html.j2:58
#: amt/site/templates/macros/form_macros.html.j2:60
msgid " from this organization? "
msgstr ""

#: amt/site/templates/macros/form_macros.html.j2:61
#: amt/site/templates/macros/form_macros.html.j2:63
msgid "Delete"
msgstr ""

#: amt/site/templates/macros/form_macros.html.j2:62
#: amt/site/templates/macros/form_macros.html.j2:64
msgid "Delete member"
msgstr ""

#: amt/site/templates/macros/form_macros.html.j2:150
#: amt/site/templates/macros/form_macros.html.j2:152
msgid "Delete file"
msgstr ""

#: amt/site/templates/macros/form_macros.html.j2:157
#: amt/site/templates/macros/form_macros.html.j2:159
msgid "Are you sure you want to delete"
msgstr ""

#: amt/site/templates/macros/table_row.html.j2:19
msgid " ago"
msgstr ""

#: amt/site/templates/macros/tasks.html.j2:11
msgid "Todo"
msgstr ""

#: amt/site/templates/macros/tasks.html.j2:18
msgid "Doing"
#: amt/site/templates/macros/tasks.html.j2:26
msgid "In review"
msgstr ""

#: amt/site/templates/macros/tasks.html.j2:25
msgid "Reviewing"
#: amt/site/templates/macros/tasks.html.j2:40
msgid "Not implemented"
msgstr ""

#: amt/site/templates/macros/tasks.html.j2:35
#: amt/site/templates/macros/tasks.html.j2:43
msgid "Unknown"
msgstr ""

Expand Down
Binary file modified amt/locale/en_US/LC_MESSAGES/messages.mo
Binary file not shown.
41 changes: 22 additions & 19 deletions amt/locale/en_US/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ msgstr ""
msgid "Compliance"
msgstr ""

#: amt/api/organization_filter_options.py:16
#: amt/api/organization_filter_options.py:17
msgid "All organizations"
msgstr ""

#: amt/api/organization_filter_options.py:17
msgid "My organizations"
msgstr ""

Expand Down Expand Up @@ -362,14 +366,14 @@ msgstr ""

#: amt/site/templates/algorithms/details_base.html.j2:28
#: amt/site/templates/algorithms/new.html.j2:153
#: amt/site/templates/macros/form_macros.html.j2:168
#: amt/site/templates/macros/form_macros.html.j2:170
#: amt/site/templates/organizations/members.html.j2:33
msgid "Yes"
msgstr ""

#: amt/site/templates/algorithms/details_base.html.j2:31
#: amt/site/templates/algorithms/new.html.j2:163
#: amt/site/templates/macros/form_macros.html.j2:173
#: amt/site/templates/macros/form_macros.html.j2:175
#: amt/site/templates/organizations/members.html.j2:36
msgid "No"
msgstr ""
Expand All @@ -385,6 +389,7 @@ msgstr ""
#: amt/site/templates/algorithms/details_compliance.html.j2:69
#: amt/site/templates/macros/editable.html.j2:28
#: amt/site/templates/macros/editable.html.j2:33
#: amt/site/templates/macros/tasks.html.j2:81
msgid "Edit"
msgstr ""

Expand All @@ -394,15 +399,17 @@ msgstr ""

#: amt/site/templates/algorithms/details_info.html.j2:20
#: amt/site/templates/algorithms/details_info.html.j2:48
#: amt/site/templates/macros/tasks.html.j2:32
#: amt/site/templates/macros/tasks.html.j2:33
msgid "Done"
msgstr ""

#: amt/site/templates/algorithms/details_info.html.j2:44
#: amt/site/templates/macros/tasks.html.j2:12
msgid "To do"
msgstr ""

#: amt/site/templates/algorithms/details_info.html.j2:46
#: amt/site/templates/macros/tasks.html.j2:19
msgid "In progress"
msgstr ""

Expand Down Expand Up @@ -610,47 +617,43 @@ msgstr ""
msgid "Algorithmic Management Toolkit (AMT)"
msgstr ""

#: amt/site/templates/macros/form_macros.html.j2:58
#: amt/site/templates/macros/form_macros.html.j2:60
msgid "Are you sure you want to remove "
msgstr ""

#: amt/site/templates/macros/form_macros.html.j2:58
#: amt/site/templates/macros/form_macros.html.j2:60
msgid " from this organization? "
msgstr ""

#: amt/site/templates/macros/form_macros.html.j2:61
#: amt/site/templates/macros/form_macros.html.j2:63
msgid "Delete"
msgstr ""

#: amt/site/templates/macros/form_macros.html.j2:62
#: amt/site/templates/macros/form_macros.html.j2:64
msgid "Delete member"
msgstr ""

#: amt/site/templates/macros/form_macros.html.j2:150
#: amt/site/templates/macros/form_macros.html.j2:152
msgid "Delete file"
msgstr ""

#: amt/site/templates/macros/form_macros.html.j2:157
#: amt/site/templates/macros/form_macros.html.j2:159
msgid "Are you sure you want to delete"
msgstr ""

#: amt/site/templates/macros/table_row.html.j2:19
msgid " ago"
msgstr ""

#: amt/site/templates/macros/tasks.html.j2:11
msgid "Todo"
msgstr ""

#: amt/site/templates/macros/tasks.html.j2:18
msgid "Doing"
#: amt/site/templates/macros/tasks.html.j2:26
msgid "In review"
msgstr ""

#: amt/site/templates/macros/tasks.html.j2:25
msgid "Reviewing"
#: amt/site/templates/macros/tasks.html.j2:40
msgid "Not implemented"
msgstr ""

#: amt/site/templates/macros/tasks.html.j2:35
#: amt/site/templates/macros/tasks.html.j2:43
msgid "Unknown"
msgstr ""

Expand Down
Binary file modified amt/locale/nl_NL/LC_MESSAGES/messages.mo
Binary file not shown.
Loading

0 comments on commit 0787177

Please sign in to comment.