generated from MinBZK/python-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
76 changed files
with
2,785 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from gettext import NullTranslations | ||
from uuid import UUID | ||
|
||
from amt.schema.webform import WebForm, WebFormField, WebFormFieldType, WebFormOption | ||
from amt.services.organizations import OrganizationsService | ||
|
||
|
||
async def get_algorithm_form( | ||
id: str, translations: NullTranslations, organizations_service: OrganizationsService, user_id: str | UUID | None | ||
) -> WebForm: | ||
_ = translations.gettext | ||
|
||
algorithm_form: WebForm = WebForm(id=id, post_url="") | ||
|
||
user_id = UUID(user_id) if isinstance(user_id, str) else user_id | ||
|
||
my_organizations = await organizations_service.get_organizations_for_user(user_id=user_id) | ||
|
||
select_organization: WebFormOption = WebFormOption(value="", display_value=_("Select organization")) | ||
|
||
algorithm_form.fields = [ | ||
WebFormField( | ||
type=WebFormFieldType.SELECT, | ||
name="organization_id", | ||
label=_("Organization"), | ||
options=[select_organization] | ||
+ [ | ||
WebFormOption(value=str(organization.id), display_value=organization.name) | ||
for organization in my_organizations | ||
], | ||
default_value="", | ||
group="1", | ||
), | ||
] | ||
|
||
return algorithm_form |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from gettext import NullTranslations | ||
|
||
from amt.schema.webform import WebForm, WebFormField, WebFormFieldType, WebFormSearchField, WebFormSubmitButton | ||
|
||
|
||
def get_organization_form(id: str, translations: NullTranslations) -> WebForm: | ||
_ = translations.gettext | ||
|
||
organization_form: WebForm = WebForm(id=id, post_url="/organizations/new") | ||
|
||
organization_form.fields = [ | ||
WebFormField( | ||
type=WebFormFieldType.TEXT, | ||
name="name", | ||
label=_("Name"), | ||
placeholder=_("Name of the organization"), | ||
attributes={"onkeyup": "amt.generate_slug('" + id + "name', '" + id + "slug')"}, | ||
group="1", | ||
), | ||
WebFormField( | ||
type=WebFormFieldType.TEXT, | ||
name="slug", | ||
description=_("The slug is the web path, like /organizations/my-organization-name"), | ||
label=_("Slug"), | ||
placeholder=_("The slug for this organization"), | ||
group="1", | ||
), | ||
WebFormSearchField( | ||
name="user_ids", | ||
label=_("Add members"), | ||
placeholder=_("Search for a person..."), | ||
search_url="/organizations/users?returnType=search_select_field", | ||
query_var_name="query", | ||
group="1", | ||
), | ||
WebFormSubmitButton(label=_("Add organization"), group="1", name="submit"), | ||
] | ||
return organization_form |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
from fastapi import APIRouter | ||
|
||
from amt.api.routes import algorithm, algorithms, auth, health, pages, root | ||
from amt.api.routes import algorithm, algorithms, auth, health, organizations, pages, root | ||
|
||
api_router = APIRouter() | ||
api_router: APIRouter = APIRouter() | ||
api_router.include_router(root.router) | ||
api_router.include_router(health.router, prefix="/health", tags=["health"]) | ||
api_router.include_router(pages.router, prefix="/pages", tags=["pages"]) | ||
api_router.include_router(algorithms.router, prefix="/algorithms", tags=["algorithms"]) | ||
api_router.include_router(algorithm.router, prefix="/algorithm", tags=["algorithm"]) | ||
api_router.include_router(auth.router, prefix="/auth", tags=["auth"]) | ||
api_router.include_router(organizations.router, prefix="/organizations", tags=["organizations"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from collections.abc import Callable | ||
|
||
from fastapi import Request | ||
|
||
from ..schema.localized_value_item import LocalizedValueItem | ||
from .localizable import LocalizableEnum, get_localized_enum, get_localized_enums | ||
|
||
|
||
class OrganizationFilterOptions(LocalizableEnum): | ||
ALL = "ALL" | ||
MY_ORGANIZATIONS = "MY_ORGANIZATIONS" | ||
|
||
@classmethod | ||
def get_display_values( | ||
cls: type["OrganizationFilterOptions"], _: Callable[[str], str] | ||
) -> dict["OrganizationFilterOptions", str]: | ||
return {cls.ALL: _("All organizations"), cls.MY_ORGANIZATIONS: _("My organizations")} | ||
|
||
|
||
def get_localized_organization_filter( | ||
key: OrganizationFilterOptions | None, request: Request | ||
) -> LocalizedValueItem | None: | ||
return get_localized_enum(key, request) | ||
|
||
|
||
def get_localized_organization_filters(request: Request) -> list[LocalizedValueItem | None]: | ||
return get_localized_enums(OrganizationFilterOptions, request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.