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
1 parent
51e9ad6
commit e756d61
Showing
75 changed files
with
5,915 additions
and
287 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
pipx install poetry | ||
poetry install | ||
poetry run playwright install --with-deps |
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 |
---|---|---|
|
@@ -27,6 +27,7 @@ __pypackages__/ | |
|
||
#mypyr | ||
.mypy_cache/ | ||
/.idea/ | ||
|
||
# macos | ||
.DS_Store | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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,7 +1,9 @@ | ||
from fastapi import APIRouter | ||
|
||
from tad.api.routes import health, root | ||
from tad.api.routes import health, pages, root, tasks | ||
|
||
api_router = 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(tasks.router, prefix="/tasks", tags=["tasks"]) |
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,9 @@ | ||
from fastapi.templating import Jinja2Templates | ||
from jinja2 import Environment | ||
|
||
from tad.core.config import settings | ||
|
||
env = Environment( | ||
autoescape=True, | ||
) | ||
templates = Jinja2Templates(directory=settings.TEMPLATE_DIR, env=env) |
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,24 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import APIRouter, Depends, Request | ||
from fastapi.responses import HTMLResponse | ||
|
||
from tad.api.routes.deps import templates | ||
from tad.services.statuses import StatusesService | ||
from tad.services.tasks import TasksService | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/", response_class=HTMLResponse) | ||
async def default_layout( | ||
request: Request, | ||
status_service: Annotated[StatusesService, Depends(StatusesService)], | ||
tasks_service: Annotated[TasksService, Depends(TasksService)], | ||
): | ||
context = { | ||
"page_title": "This is the page title", | ||
"tasks_service": tasks_service, | ||
"statuses_service": status_service, | ||
} | ||
return templates.TemplateResponse(request=request, name="default_layout.jinja", context=context) |
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,16 @@ | ||
from fastapi import APIRouter, Request | ||
from fastapi.responses import HTMLResponse | ||
from fastapi import APIRouter | ||
from fastapi.responses import FileResponse, RedirectResponse | ||
|
||
from tad.api.deps import templates | ||
from tad.core.config import settings | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/") | ||
async def base(request: Request) -> HTMLResponse: | ||
return templates.TemplateResponse(request=request, name="root/index.html") | ||
async def base() -> RedirectResponse: | ||
return RedirectResponse("/pages/") | ||
|
||
|
||
@router.get("/favicon.ico", include_in_schema=False) | ||
async def favicon(): | ||
return FileResponse(settings.STATIC_DIR + "/favicon.ico") |
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,41 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import APIRouter, Depends, Request, status | ||
from fastapi.responses import HTMLResponse | ||
|
||
from tad.api.routes.deps import templates | ||
from tad.schema.task import MovedTask | ||
from tad.services.tasks import TasksService | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.patch("/") | ||
async def move_task( | ||
request: Request, moved_task: MovedTask, tasks_service: Annotated[TasksService, Depends(TasksService)] | ||
) -> HTMLResponse: | ||
""" | ||
Move a task through an API call. | ||
:param tasks_service: the task service | ||
:param request: the request object | ||
:param moved_task: the move task object | ||
:return: a HTMLResponse object, in this case the html code of the card that was moved | ||
""" | ||
try: | ||
# because htmx form always sends a value and siblings are optional, we use -1 for None and convert it here | ||
if moved_task.next_sibling_id == -1: | ||
moved_task.next_sibling_id = None | ||
if moved_task.previous_sibling_id == -1: | ||
moved_task.previous_sibling_id = None | ||
task = tasks_service.move_task( | ||
moved_task.id, | ||
moved_task.status_id, | ||
moved_task.previous_sibling_id, | ||
moved_task.next_sibling_id, | ||
) | ||
# todo(Robbert) add error handling for input error or task error handling | ||
return templates.TemplateResponse(request=request, name="task.jinja", context={"task": task}) | ||
except Exception: | ||
return templates.TemplateResponse( | ||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, request=request, name="error.jinja" | ||
) |
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 |
---|---|---|
@@ -1,10 +1,18 @@ | ||
from sqlalchemy.engine.base import Engine | ||
from sqlmodel import Session, create_engine, select | ||
|
||
from tad.core.config import settings | ||
|
||
engine = create_engine(settings.SQLALCHEMY_DATABASE_URI) | ||
_engine: None | Engine = None | ||
|
||
|
||
def get_engine() -> Engine: | ||
global _engine | ||
if _engine is None: | ||
_engine = create_engine(settings.SQLALCHEMY_DATABASE_URI) | ||
return _engine | ||
|
||
|
||
async def check_db(): | ||
with Session(engine) as session: | ||
with Session(get_engine()) as session: | ||
session.exec(select(1)) |
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
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,60 @@ | ||
"""Create the user, status and task tables, drop table hero | ||
Revision ID: eb2eed884ae9 | ||
Revises: | ||
Create Date: 2024-05-14 13:36:23.551663 | ||
""" | ||
|
||
from collections.abc import Sequence | ||
|
||
import sqlalchemy as sa | ||
import sqlmodel.sql.sqltypes | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "eb2eed884ae9" | ||
down_revision: str | None = None | ||
branch_labels: str | Sequence[str] | None = None | ||
depends_on: str | Sequence[str] | None = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("hero") | ||
op.create_table( | ||
"status", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("sort_order", sa.Float(), nullable=False), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
op.create_table( | ||
"user", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("avatar", sqlmodel.sql.sqltypes.AutoString(), nullable=True), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
op.create_table( | ||
"task", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("title", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("sort_order", sa.Float(), nullable=False), | ||
sa.Column("status_id", sa.Integer(), nullable=False), | ||
sa.Column("user_id", sa.Integer(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["user_id"], | ||
["user.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# we do not delete any tables on a downgrade | ||
pass | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
# ### end Alembic commands ### |
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,3 +1,5 @@ | ||
from .hero import Hero | ||
from .status import Status | ||
from .task import Task | ||
from .user import User | ||
|
||
__all__ = ["Hero"] | ||
__all__ = ["Task", "Status", "User"] |
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,7 @@ | ||
from sqlmodel import Field, SQLModel # type: ignore | ||
|
||
|
||
class Status(SQLModel, table=True): | ||
id: int | None = Field(default=None, primary_key=True) | ||
name: str | ||
sort_order: float |
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,12 @@ | ||
from sqlmodel import Field as SQLField # type: ignore | ||
from sqlmodel import SQLModel | ||
|
||
|
||
class Task(SQLModel, table=True): | ||
id: int | None = SQLField(default=None, primary_key=True) | ||
title: str | ||
description: str | ||
sort_order: float | ||
status_id: int | None = SQLField(default=None, foreign_key="status.id") | ||
user_id: int | None = SQLField(default=None, foreign_key="user.id") | ||
# todo(robbert) Tasks probably are grouped (and sub-grouped), so we probably need a reference to a group_id |
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,6 +1,7 @@ | ||
from sqlmodel import Field, SQLModel # type: ignore | ||
|
||
|
||
class Hero(SQLModel, table=True): | ||
class User(SQLModel, table=True): | ||
id: int = Field(default=None, primary_key=True) | ||
name: str | ||
avatar: str | None |
File renamed without changes.
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,10 @@ | ||
from collections.abc import Generator | ||
|
||
from sqlmodel import Session | ||
|
||
from tad.core.db import get_engine | ||
|
||
|
||
def get_session() -> Generator[Session, None, None]: | ||
with Session(get_engine()) as session: | ||
yield session |
Oops, something went wrong.