WIP: add HTML form for editing comics
This commit is contained in:
@@ -2,7 +2,8 @@ from typing import List, AnyStr
|
|||||||
from fastapi import APIRouter, HTTPException, status
|
from fastapi import APIRouter, HTTPException, status
|
||||||
|
|
||||||
from src.apis.utils import SessionDep
|
from src.apis.utils import SessionDep
|
||||||
from src.db.repository.comic import get_artist_details, list_comics, get_issue_details
|
from src.db.repository.comics.artist import get_artist_details
|
||||||
|
from src.db.repository.comics.comic import list_comics, get_issue_details
|
||||||
from src.schema.comics.comic import ComicResponse, ComicDetailsResponse, get_comic_details, get_short_info
|
from src.schema.comics.comic import ComicResponse, ComicDetailsResponse, get_comic_details, get_short_info
|
||||||
from src.schema.comics.artist import ArtistCreation, ArtistDetailResponse, ArtistResponse
|
from src.schema.comics.artist import ArtistCreation, ArtistDetailResponse, ArtistResponse
|
||||||
from src.db.models.comic import Comic, Artist, Issue
|
from src.db.models.comic import Comic, Artist, Issue
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
import uuid
|
|
||||||
from datetime import datetime
|
|
||||||
from typing import List, Type, AnyStr
|
|
||||||
|
|
||||||
from sqlalchemy.orm import Session
|
|
||||||
|
|
||||||
from src.core.log_conf import logger
|
|
||||||
from src.db.models.comic import Artist, Comic, Issue, WorkType
|
|
||||||
from src.schema.comics.artist import ArtistDetailResponse
|
|
||||||
from src.schema.comics.issue import IssueDetailsResponse
|
|
||||||
from src.schema.comics.worktype import AddWorkType
|
|
||||||
|
|
||||||
|
|
||||||
def get_artist_details(artist: Artist) -> ArtistDetailResponse:
|
|
||||||
works = {}
|
|
||||||
for work in artist.comic_works:
|
|
||||||
work_type = work.work_type.name
|
|
||||||
comic_title = work.comic.title
|
|
||||||
if work_type in works:
|
|
||||||
works[work_type].append(comic_title)
|
|
||||||
else:
|
|
||||||
works[work_type] = [comic_title]
|
|
||||||
response = ArtistDetailResponse(
|
|
||||||
id=artist.id,
|
|
||||||
name=artist.name,
|
|
||||||
works=works
|
|
||||||
)
|
|
||||||
return response
|
|
||||||
|
|
||||||
def list_comics(db: Session) -> List[Type[Comic]]:
|
|
||||||
comics = db.query(Comic).all()
|
|
||||||
return comics
|
|
||||||
|
|
||||||
|
|
||||||
def get_issue_details(issue: Issue) -> IssueDetailsResponse:
|
|
||||||
response = IssueDetailsResponse(
|
|
||||||
id=issue.id,
|
|
||||||
issue_number=issue.issue_number,
|
|
||||||
in_stock=issue.in_stock,
|
|
||||||
is_read=issue.is_read,
|
|
||||||
comic_id=issue.comic_id,
|
|
||||||
volume_id=issue.volume_id
|
|
||||||
)
|
|
||||||
return response
|
|
||||||
|
|
||||||
def create_new_worktype(work: AddWorkType, db: Session) -> WorkType:
|
|
||||||
worktype = WorkType()
|
|
||||||
worktype.id = str(uuid.uuid4())
|
|
||||||
worktype.created_date = datetime.now()
|
|
||||||
worktype.last_modified_date = datetime.now()
|
|
||||||
worktype.name = work.worktype
|
|
||||||
db.add(worktype)
|
|
||||||
db.commit()
|
|
||||||
db.refresh(worktype)
|
|
||||||
logger.info(f"create_new_worktype: {worktype}")
|
|
||||||
return worktype
|
|
||||||
|
|
||||||
|
|
||||||
def update_worktype(work: AddWorkType, worktype_id: AnyStr, db: Session) -> WorkType:
|
|
||||||
logger.info("update worktype")
|
|
||||||
worktype = db.get(WorkType, worktype_id)
|
|
||||||
worktype.name = work.worktype
|
|
||||||
db.add(worktype)
|
|
||||||
db.commit()
|
|
||||||
db.refresh(worktype)
|
|
||||||
return worktype
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
from fastapi import APIRouter, Request
|
from fastapi import APIRouter, Request
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
|
|
||||||
from src.core.config import settings
|
|
||||||
from src.webapps.admin import route_admin
|
from src.webapps.admin import route_admin
|
||||||
from src.webapps.auth import route_login
|
from src.webapps.auth import route_login
|
||||||
from src.webapps.comic import route_comics, route_worktype, route_artists
|
from src.webapps.comic import route_comics, route_worktype, route_artists
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
from fastapi import Request
|
|
||||||
from typing import List, Optional
|
|
||||||
|
|
||||||
|
|
||||||
class AddWorktypeForm:
|
|
||||||
def __init__(self, request: Request):
|
|
||||||
self.request = request
|
|
||||||
self.errors: List = []
|
|
||||||
self.worktype: Optional[str] = None
|
|
||||||
|
|
||||||
async def load_data(self):
|
|
||||||
form = await self.request.form()
|
|
||||||
self.worktype = form.get("worktype")
|
|
||||||
|
|
||||||
def is_valid(self):
|
|
||||||
if not self.worktype or (len(self.worktype) == 0):
|
|
||||||
self.errors.append("WorkType cannot be empty")
|
|
||||||
if not self.errors:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
from fastapi import APIRouter, Form, Request, status
|
from fastapi import APIRouter, Form, Request, status
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
|
from fastapi.responses import RedirectResponse
|
||||||
|
|
||||||
from src.apis.utils import SessionDep
|
from src.apis.utils import SessionDep
|
||||||
from src.db.models.comic import Comic, Publisher, Issue
|
from src.db.models.comic import Comic, Publisher, Issue
|
||||||
|
|||||||
Reference in New Issue
Block a user