make details for Comic, Artist and Issue clickable, add CustomField to select Comic and Issue
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import Dict, List, Optional
|
||||
from typing import Dict, List, Optional, Any
|
||||
from natsort import natsorted
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String, Boolean, func
|
||||
from sqlalchemy.orm import relationship, Mapped, mapped_column
|
||||
@@ -48,10 +48,10 @@ class Comic(Base, BaseMixin):
|
||||
def __str__(self):
|
||||
return f'{self.title}({self.id})'
|
||||
|
||||
def get_artists(self) -> Dict[str, List[str]]:
|
||||
works: Dict[str, List[str]] = {}
|
||||
def get_artists(self) -> Dict[Any, List[Any]]:
|
||||
works: Dict[Any, List[Any]] = {}
|
||||
for work in self.comic_works:
|
||||
work_type = work.work_type.name
|
||||
work_type = work.work_type
|
||||
artist = work.artist
|
||||
if work_type in works:
|
||||
works[work_type].append(artist)
|
||||
@@ -107,6 +107,18 @@ class Issue(Base, BaseMixin):
|
||||
story_arc = relationship("StoryArc", back_populates="issues")
|
||||
issue_works = relationship("IssueWork")
|
||||
|
||||
def get_artists(self) -> Dict[Any, List[Any]]:
|
||||
works: Dict[Any, List[Any]] = {}
|
||||
for work in self.issue_works:
|
||||
work_type = work.work_type
|
||||
artist = work.artist
|
||||
if work_type in works:
|
||||
works[work_type].append(artist)
|
||||
else:
|
||||
works[work_type] = [artist]
|
||||
return works
|
||||
|
||||
|
||||
class Artist(Base, BaseMixin):
|
||||
__tablename__ = "artist"
|
||||
name = Column(String, nullable=False)
|
||||
@@ -114,10 +126,10 @@ class Artist(Base, BaseMixin):
|
||||
comic_works = relationship("ComicWork")
|
||||
issue_works = relationship("IssueWork")
|
||||
|
||||
def get_comics(self) -> Dict[str, List[str]]:
|
||||
works: Dict[str, List[str]] = {}
|
||||
def get_comics(self) -> Dict[Any, List[Comic]]:
|
||||
works: Dict[Any, List[Comic]] = {}
|
||||
for work in self.comic_works:
|
||||
work_type = work.work_type.name
|
||||
work_type = work.work_type
|
||||
comic = work.comic
|
||||
if work_type in works:
|
||||
works[work_type].append(comic)
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<td colspan="2">
|
||||
{% for work in artist.get_comics() %}
|
||||
<p>
|
||||
{{work}}:
|
||||
<a href="/comic/worktypes/{{work.id}}">{{work.name}}</a>
|
||||
<ul>
|
||||
{% for comic in artist.get_comics()[work] %}
|
||||
<li><a href="/comic/comics/{{comic.id}}">{{comic.title}}</a></li>
|
||||
@@ -47,6 +47,10 @@
|
||||
<th scope="row">Data Modified</th>
|
||||
<td colspan="2">{{artist.last_modified_date}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Data Version</th>
|
||||
<td colspan="2">{{artist.version}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<td colspan="2">
|
||||
{% for work in comic.get_artists() %}
|
||||
<p>
|
||||
{{work}}:
|
||||
<a href="/comic/worktypes/{{work.id}}">{{work.name}}</a>
|
||||
<ul>
|
||||
{% for artist in comic.get_artists()[work] %}
|
||||
<li><a href="/comic/artists/{{artist.id}}">{{artist.name}}</a></li>
|
||||
|
||||
@@ -10,9 +10,15 @@
|
||||
{% endwith %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<form class="d-flex" action="/comic/comics/">
|
||||
<input class="form-control me-2" name="query" id="autocomplete" type="search" placeholder="Search" aria-label="Search">
|
||||
Completed<input type="checkbox" name="completed" {% if request.query_params.get("completed")=="on" %}checked{% endif %} aria-label="Completed">
|
||||
Order<input type="checkbox" name="order" {% if request.query_params.get("order")=="on" %}checked{% endif %} aria-label="Order">
|
||||
<button class="btn btn-outline-success" type="submit">Search</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="row">
|
||||
<h1 class="display-5">Comics..</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<table class="table table-hover">
|
||||
|
||||
@@ -50,12 +50,29 @@
|
||||
<a href="/comic/comics/{{issue.comic_id}}">{{issue.comic.title}}</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% if issue.volume %}
|
||||
<tr>
|
||||
<th scope="row">Volume</th>
|
||||
<td colspan="2">
|
||||
<a href="/comic/comics/{{issue.volume_id}}">{{issue.volume.name}}</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th scope="row">Works</th>
|
||||
<td colspan="2">
|
||||
{% for work in issue.get_artists() %}
|
||||
<p>
|
||||
<a href="/comic/worktypes/{{work.id}}">{{work.name}}</a>
|
||||
<ul>
|
||||
{% for artist in issue.get_artists()[work] %}
|
||||
<li><a href="/comic/artists/{{artist.id}}">{{artist.name}}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</p>
|
||||
{% endfor %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Data Created</th>
|
||||
<td colspan="2">{{issue.created_date}}</td>
|
||||
|
||||
@@ -10,7 +10,24 @@ router = APIRouter(include_in_schema=False, prefix="/comic")
|
||||
|
||||
@router.get("/comics")
|
||||
def get_comics(db: SessionDep, request: Request, msg: str | None = None):
|
||||
comics = db.query(Comic).all()
|
||||
params = request.query_params
|
||||
query = params.get("query")
|
||||
filter = {}
|
||||
completed = params.get('completed') == "on"
|
||||
if completed:
|
||||
filter['completed'] = True
|
||||
order = params.get("order") == "on"
|
||||
if order:
|
||||
filter['current_order'] = True
|
||||
if query is not None and len(query) > 0:
|
||||
filter['title'] = query
|
||||
if len(filter) > 0:
|
||||
if "title" in filter:
|
||||
comics = db.query(Comic).filter(Comic.title.ilike(f'%{query}%'))
|
||||
else:
|
||||
comics = db.query(Comic).filter_by(**filter).all()
|
||||
else:
|
||||
comics = db.query(Comic).all()
|
||||
return templates.TemplateResponse("comic/comics.html", {"request": request, "msg": msg, "comics": comics})
|
||||
|
||||
@router.get("/comics/{comic_id}")
|
||||
|
||||
Reference in New Issue
Block a user