add form for editing artist
This commit is contained in:
@@ -51,7 +51,11 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div><a href="/comic/artists" class="btn btn-outline-primary btn-sm active" role="button" aria-pressed="true">Back to list</a></div>
|
<div>
|
||||||
|
<a href="/comic/artists" class="btn btn-outline-primary btn-sm active" role="button" aria-pressed="true">Back to list</a>
|
||||||
|
<a href="/comic/artist/edit/{{artist.id}}" class="btn btn-outline-primary btn-sm active" role="button" aria-pressed="true">Edit</a>
|
||||||
|
<a href="/comic/artist/delete/{{artist.id}}" class="btn btn-outline-danger btn-sm active" role="button" aria-pressed="true">Delete</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
{% extends "shared/base.html" %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
<title>Edit Artist</title>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="text-danger font-weight-bold">
|
||||||
|
{% for error in errors %}
|
||||||
|
<li>{{error}}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row my-5">
|
||||||
|
<h3 class="text-center display-4">Edit an Artist entry</h3>
|
||||||
|
<form method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<input type="text" required class="form-control" name="artist.name" value="{{artist_name}}" placeholder="Artist name here">
|
||||||
|
<input type="text" required class="form-control" name="artist.link" value="{{artist_link}}" placeholder="Web link for artist here">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button type="submit" class="btn btn-primary">Submit</button>
|
||||||
|
<button type="cancel" class="btn btn-primary">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -4,13 +4,14 @@ from fastapi.templating import Jinja2Templates
|
|||||||
from src.core.config import settings
|
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
|
from src.webapps.comic import route_comics, route_worktype, route_artists
|
||||||
from src.webapps.media import route_media, route_videos
|
from src.webapps.media import route_media, route_videos
|
||||||
|
|
||||||
templates = Jinja2Templates(directory="src/templates")
|
templates = Jinja2Templates(directory="src/templates")
|
||||||
|
|
||||||
api_router = APIRouter()
|
api_router = APIRouter()
|
||||||
api_router.include_router(route_comics.router)
|
api_router.include_router(route_comics.router)
|
||||||
|
api_router.include_router(route_artists.router)
|
||||||
api_router.include_router(route_worktype.router)
|
api_router.include_router(route_worktype.router)
|
||||||
api_router.include_router(route_media.router)
|
api_router.include_router(route_media.router)
|
||||||
api_router.include_router(route_videos.router)
|
api_router.include_router(route_videos.router)
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
from fastapi import APIRouter, Request, responses, status
|
||||||
|
from fastapi.templating import Jinja2Templates
|
||||||
|
from fastapi.responses import RedirectResponse
|
||||||
|
|
||||||
|
from src.apis.utils import SessionDep
|
||||||
|
from src.db.models.comic import Artist
|
||||||
|
from typing import AnyStr
|
||||||
|
|
||||||
|
#from src.db.repository.comic import create_new_worktype, update_worktype
|
||||||
|
from src.main import logger
|
||||||
|
#from src.schema.comics.worktype import AddWorkType
|
||||||
|
#from src.webapps.comic.forms import AddWorktypeForm
|
||||||
|
|
||||||
|
templates = Jinja2Templates(directory="src/templates")
|
||||||
|
router = APIRouter(include_in_schema=False, prefix="/comic")
|
||||||
|
|
||||||
|
@router.get("/artists")
|
||||||
|
def get_artists(db: SessionDep, request: Request, msg: str | None = None):
|
||||||
|
artists = db.query(Artist).all()
|
||||||
|
return templates.TemplateResponse("comic/artists.html", {"request": request, "msg": msg, "artists": artists})
|
||||||
|
|
||||||
|
@router.get("/artists/{artist_id}")
|
||||||
|
def artist_detail(artist_id: AnyStr, request: Request, db: SessionDep):
|
||||||
|
artist = db.get(Artist, str(artist_id))
|
||||||
|
return templates.TemplateResponse("comic/artist_detail.html", {"request": request, "artist": artist})
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/artist/edit/{artist_id}")
|
||||||
|
def edit_artist(db: SessionDep, request: Request, artist_id: str):
|
||||||
|
artist = db.get(Artist, artist_id)
|
||||||
|
return templates.TemplateResponse("comic/artist_edit.html", {"request": request, "artist_name": artist.name, "artist_link": artist.weblink})
|
||||||
|
|
||||||
|
@router.post("/artist/edit/{artist_id}")
|
||||||
|
async def edit_artist(request: Request, db: SessionDep, artist_id: str):
|
||||||
|
form = AddArtistForm(request)
|
||||||
|
await form.load_data()
|
||||||
|
if form.is_valid():
|
||||||
|
try:
|
||||||
|
artist = AddArtist(**form.__dict__)
|
||||||
|
artist = update_artist(artist=artist, artist_id=artist_id, db=db)
|
||||||
|
return RedirectResponse(f"/comic/artists/{artist.id}", status_code=status.HTTP_303_SEE_OTHER)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
form.__dict__.get("errors").append("artist already added")
|
||||||
|
return templates.TemplateResponse("comic/artist_edit.html", form.__dict__)
|
||||||
|
return templates.TemplateResponse("comic/artist_edit.html", form.__dict__)
|
||||||
|
|
||||||
|
@router.get("/artist/delete/{artist_id}")
|
||||||
|
async def delete_artist(db: SessionDep, request: Request, artist_id: str):
|
||||||
|
artist = db.get(Artist, artist_id)
|
||||||
|
db.delete(artist)
|
||||||
|
db.commit()
|
||||||
|
return RedirectResponse("/comic/artists", status_code=status.HTTP_303_SEE_OTHER)
|
||||||
@@ -18,16 +18,6 @@ def comic_details(comic_id: AnyStr, request: Request, db: SessionDep):
|
|||||||
comic = db.get(Comic, comic_id)
|
comic = db.get(Comic, comic_id)
|
||||||
return templates.TemplateResponse("comic/comic_detail.html", {"request": request, "comic":comic})
|
return templates.TemplateResponse("comic/comic_detail.html", {"request": request, "comic":comic})
|
||||||
|
|
||||||
@router.get("/artists")
|
|
||||||
def get_artists(db: SessionDep, request: Request, msg: str | None = None):
|
|
||||||
artists = db.query(Artist).all()
|
|
||||||
return templates.TemplateResponse("comic/artists.html", {"request": request, "msg": msg, "artists": artists})
|
|
||||||
|
|
||||||
@router.get("/artists/{artist_id}")
|
|
||||||
def artist_detail(artist_id: AnyStr, request: Request, db: SessionDep):
|
|
||||||
artist = db.get(Artist, str(artist_id))
|
|
||||||
return templates.TemplateResponse("comic/artist_detail.html", {"request": request, "artist": artist})
|
|
||||||
|
|
||||||
@router.get("/publishers")
|
@router.get("/publishers")
|
||||||
def get_publishers(db: SessionDep, request: Request, msg: str | None = None):
|
def get_publishers(db: SessionDep, request: Request, msg: str | None = None):
|
||||||
publishers = db.query(Publisher).all()
|
publishers = db.query(Publisher).all()
|
||||||
|
|||||||
Reference in New Issue
Block a user