Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make status fields static instead of dynamic #111

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ docker compose up

We use babel for translations and a custom yaml for dynamic translations. Babel does not support Frysian, so we added a custom piece of code to support this. To generate, update or compile the language files, use the script in ./script/translate.

### Known quirks

When running the script/translate update command, Python may give the error

```
ValueError: Unknown extraction method 'jinja2'
```

The solution for this error, is to upgrade/install the setuptools:
```
pip install --upgrade setuptools
```


## Testing, Linting etc

For testing, linting and other feature we use several tools. You can look up the documentation on how to use these:
Expand Down
9 changes: 2 additions & 7 deletions amt/api/routes/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi.responses import HTMLResponse

from amt.api.deps import templates
from amt.services.statuses import StatusesService
from amt.enums.status import Status
from amt.services.tasks import TasksService

router = APIRouter()
Expand All @@ -13,12 +13,7 @@
@router.get("/", response_class=HTMLResponse)
async def default_layout(
request: Request,
status_service: Annotated[StatusesService, Depends(StatusesService)],
tasks_service: Annotated[TasksService, Depends(TasksService)],
) -> HTMLResponse:
context = {
"page_title": "This is the page title",
"tasks_service": tasks_service,
"statuses_service": status_service,
}
context = {"page_title": "This is the page title", "tasks_service": tasks_service, "statuses": Status}
return templates.TemplateResponse(request, "pages/index.html.j2", context)
5 changes: 2 additions & 3 deletions amt/api/routes/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from amt.api.deps import templates
from amt.core.exceptions import NotFound
from amt.enums.status import Status
from amt.services.projects import ProjectsService
from amt.services.statuses import StatusesService
from amt.services.tasks import TasksService

router = APIRouter()
Expand All @@ -19,14 +19,13 @@ async def get_root(
request: Request,
project_id: int,
projects_service: Annotated[ProjectsService, Depends(ProjectsService)],
status_service: Annotated[StatusesService, Depends(StatusesService)],
tasks_service: Annotated[TasksService, Depends(TasksService)],
) -> HTMLResponse:
project = projects_service.get(project_id)

context = {
"tasks_service": tasks_service,
"statuses_service": status_service,
"statuses": Status,
"project": project,
}

Expand Down
36 changes: 6 additions & 30 deletions amt/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from sqlmodel import Session, SQLModel, create_engine, select, update

from amt.core.config import get_settings
from amt.models import Status, Task, User
from amt.enums.status import Status
from amt.models import Task, User

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -36,9 +37,6 @@ def remove_old_demo_objects(session: Session) -> None:
user = session.exec(select(User).where(User.name == "Robbert")).first()
if user:
session.delete(user)
status = session.exec(select(Status).where(Status.name == "todo")).first()
if status:
session.delete(status)
session.commit()


Expand All @@ -54,8 +52,7 @@ def init_db() -> None:
logger.info("Creating demo data")
remove_old_demo_objects(session)
add_demo_users(session, ["default user"])
demo_statuses = add_demo_statuses(session, ["todo", "review", "in_progress", "done"])
add_demo_tasks(session, demo_statuses[0], 3)
add_demo_tasks(session, Status.TODO, 3)
logger.info("Finished initializing database")


Expand All @@ -67,34 +64,13 @@ def add_demo_users(session: Session, user_names: list[str]) -> None:
session.commit()


def add_demo_tasks(session: Session, status: Status | None, number_of_tasks: int) -> None:
if status is None:
return
def add_demo_tasks(session: Session, status: Status, number_of_tasks: int) -> None:
for index in range(1, number_of_tasks + 1):
title = "Example task " + str(index)
task = session.exec(select(Task).where(Task.title == title)).first()
if not task:
session.add(
Task(
title=title,
description="Example description " + str(index),
sort_order=index,
status_id=status.id,
)
Task(title=title, description="Example description " + str(index), sort_order=index, status_id=status)
)
session.exec(update(Task).values(status_id=status.id)) # type: ignore
session.exec(update(Task).values(status_id=status)) # type: ignore
session.commit()


def add_demo_statuses(session: Session, statuses: list[str]) -> list[Status]:
return_statuses: list[Status] = []
for index, status_name in enumerate(statuses):
status = session.exec(select(Status).where(Status.name == status_name)).first()
if not status:
status = Status(name=status_name, sort_order=index + 1)
session.add(status)
return_statuses.append(status)
session.commit()
for return_status in return_statuses:
session.refresh(return_status)
return return_statuses
Empty file added amt/enums/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions amt/enums/status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from enum import IntEnum


class Status(IntEnum):
TODO = 1
DOING = 2
REVIEW = 3
DONE = 4
4 changes: 0 additions & 4 deletions amt/languages/en.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
todo: ToDo
review: Review
done: Done
in_progress: In Progress
4 changes: 0 additions & 4 deletions amt/languages/fy.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
todo: Dwaan
review: Resinsje
in_progress: Dwaande
done: Dien
# please note we have custom translations for weekdays and months because babel does not support Frysian
weekdays: # note, the order corresponds to the weekdays (number) used by date formatting
- snein
Expand Down
4 changes: 0 additions & 4 deletions amt/languages/nl.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
todo: Te doen
review: Beoordelen
done: Afgerond
in_progress: Onderhanden
22 changes: 21 additions & 1 deletion amt/locale/base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-07-26 10:33+0200\n"
"POT-Creation-Date: 2024-07-26 13:53+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -46,6 +46,26 @@ msgstr ""
msgid "Algorithmic Management Toolkit (AMT)"
msgstr ""

#: amt/site/templates/macros/render.html.j2:6
msgid "Todo"
msgstr ""

#: amt/site/templates/macros/render.html.j2:8
msgid "Doing"
msgstr ""

#: amt/site/templates/macros/render.html.j2:10
msgid "Reviewing"
msgstr ""

#: amt/site/templates/macros/render.html.j2:12
msgid "Done"
msgstr ""

#: amt/site/templates/macros/render.html.j2:14
msgid "Unknown"
msgstr ""

#: amt/site/templates/projects/new.html.j2:4
msgid "New Project"
msgstr ""
Expand Down
Binary file modified amt/locale/en_US/LC_MESSAGES/messages.mo
Binary file not shown.
48 changes: 22 additions & 26 deletions amt/locale/en_US/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-07-26 10:33+0200\n"
"PO-Revision-Date: 2024-07-02 11:20+0200\n"
"POT-Creation-Date: 2024-07-26 13:53+0200\n"
"PO-Revision-Date: 2024-07-25 21:01+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
"Language-Team: en_US <LL@li.org>\n"
Expand Down Expand Up @@ -47,6 +47,26 @@ msgstr ""
msgid "Algorithmic Management Toolkit (AMT)"
msgstr ""

#: amt/site/templates/macros/render.html.j2:6
msgid "Todo"
msgstr ""

#: amt/site/templates/macros/render.html.j2:8
msgid "Doing"
msgstr ""

#: amt/site/templates/macros/render.html.j2:10
msgid "Reviewing"
msgstr ""

#: amt/site/templates/macros/render.html.j2:12
msgid "Done"
msgstr ""

#: amt/site/templates/macros/render.html.j2:14
msgid "Unknown"
msgstr ""

#: amt/site/templates/projects/new.html.j2:4
msgid "New Project"
msgstr ""
Expand All @@ -62,27 +82,3 @@ msgstr ""
#: amt/site/templates/projects/new.html.j2:18
msgid "Create Project"
msgstr ""

#~ msgid "Algorithmic Management Toolkit"
#~ msgstr ""

#~ msgid "Language"
#~ msgstr ""

#~ msgid "Algorithmic Management Toolkit (AMT)"
#~ msgstr ""

#~ msgid "Not found"
#~ msgstr ""

#~ msgid "New Project"
#~ msgstr ""

#~ msgid "Project name"
#~ msgstr ""

#~ msgid "Selected Instruments"
#~ msgstr ""

#~ msgid "Create Project"
#~ msgstr ""
Binary file modified amt/locale/nl_FY/LC_MESSAGES/messages.mo
Binary file not shown.
48 changes: 22 additions & 26 deletions amt/locale/nl_FY/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-07-26 10:33+0200\n"
"PO-Revision-Date: 2024-07-02 11:05+0200\n"
"POT-Creation-Date: 2024-07-26 13:53+0200\n"
"PO-Revision-Date: 2024-07-25 21:01+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: nl_FY\n"
"Language-Team: nl_FY <LL@li.org>\n"
Expand Down Expand Up @@ -47,6 +47,26 @@ msgstr ""
msgid "Algorithmic Management Toolkit (AMT)"
msgstr ""

#: amt/site/templates/macros/render.html.j2:6
msgid "Todo"
msgstr "Dwaan"

#: amt/site/templates/macros/render.html.j2:8
msgid "Doing"
msgstr "Dwaande"

#: amt/site/templates/macros/render.html.j2:10
msgid "Reviewing"
msgstr "Resinsje"

#: amt/site/templates/macros/render.html.j2:12
msgid "Done"
msgstr "Dien"

#: amt/site/templates/macros/render.html.j2:14
msgid "Unknown"
msgstr ""

#: amt/site/templates/projects/new.html.j2:4
msgid "New Project"
msgstr ""
Expand All @@ -62,27 +82,3 @@ msgstr ""
#: amt/site/templates/projects/new.html.j2:18
msgid "Create Project"
msgstr ""

#~ msgid "Algorithm Management Toolkit"
#~ msgstr "Algoritme Behear Toolkit"

#~ msgid "Language"
#~ msgstr "Taal"

#~ msgid "Algorithmic Management Toolkit (AMT)"
#~ msgstr "Algoritme Behear Toolkit (AMT)"

#~ msgid "Not found"
#~ msgstr "Niet gevonden"

#~ msgid "New Project"
#~ msgstr "Nieuw Project"

#~ msgid "Project name"
#~ msgstr "Project naam"

#~ msgid "Selected Instruments"
#~ msgstr "Kies instrument"

#~ msgid "Create Project"
#~ msgstr "Maak project"
Binary file modified amt/locale/nl_NL/LC_MESSAGES/messages.mo
Binary file not shown.
Loading