add display for WorkType
This commit is contained in:
@@ -110,6 +110,17 @@ class WorkType(Base, BaseMixin):
|
||||
name = Column(String, nullable=False, unique=True)
|
||||
comic_works = relationship("ComicWork")
|
||||
|
||||
def get_artists(self) -> Dict[str, List[str]]:
|
||||
works: Dict[str, List[str]] = {}
|
||||
for work in self.comic_works:
|
||||
comic = work.comic.title
|
||||
artist = work.artist
|
||||
if comic in works:
|
||||
works[comic].append(artist)
|
||||
else:
|
||||
works[comic] = [artist]
|
||||
return works
|
||||
|
||||
def __repr__(self):
|
||||
return f'Worktype({self.id} {self.version} {self.name} {len(self.comic_works)})'
|
||||
|
||||
|
||||
@@ -98,3 +98,14 @@ class MediaVideo(Base, BaseMixin):
|
||||
title = Column(String)
|
||||
url = Column(String, unique=True)
|
||||
should_download = Column(Boolean)
|
||||
|
||||
def __repr__(self):
|
||||
return f'MediaFile({self.id} {self.title} {self.url})'
|
||||
|
||||
def __str__(self):
|
||||
if self.title is None:
|
||||
return f'{self.url}({self.id})'
|
||||
else:
|
||||
return f'{self.title}({self.id})'
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import List, Type
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from src.db.models.comic import Artist, Comic, Issue
|
||||
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.webapps.comic.forms import AddWorktypeForm
|
||||
|
||||
|
||||
def get_artist_details(artist: Artist) -> ArtistDetailResponse:
|
||||
@@ -38,3 +41,15 @@ def get_issue_details(issue: Issue) -> IssueDetailsResponse:
|
||||
volume_id=issue.volume_id
|
||||
)
|
||||
return response
|
||||
|
||||
def create_new_worktype(work: AddWorktypeForm, 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)
|
||||
print(worktype)
|
||||
return worktype
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from src.db.models.media import MediaVideo
|
||||
from src.webapps.media.forms import AddLinkForm
|
||||
|
||||
|
||||
def create_new_video(video: AddLinkForm, db: Session) -> MediaVideo:
|
||||
print(video.url)
|
||||
return MediaVideo()
|
||||
media_video = MediaVideo()
|
||||
media_video.id = str(uuid.uuid4())
|
||||
media_video.url = video.url
|
||||
media_video.created_date = datetime.now()
|
||||
media_video.last_modified_date = datetime.now()
|
||||
media_video.review = True
|
||||
media_video.should_download = True
|
||||
db.add(media_video)
|
||||
db.commit()
|
||||
db.refresh(media_video)
|
||||
print(media_video)
|
||||
return media_video
|
||||
|
||||
Reference in New Issue
Block a user