setup basic project with Python Robyn
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""
|
||||
Definition of models
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import create_engine, func
|
||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, sessionmaker
|
||||
|
||||
DATABASE_URL = "sqlite:///./kontor.db"
|
||||
|
||||
engine = create_engine(DATABASE_URL)
|
||||
SESSION_LOCAL = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
"""
|
||||
Base class for all Models
|
||||
"""
|
||||
|
||||
|
||||
class BaseMixin:
|
||||
"""
|
||||
Base mixin to provide standard fields id, version, created_date, last_modified_date
|
||||
"""
|
||||
|
||||
id: Mapped[str] = mapped_column(primary_key=True, default=str(uuid.uuid4()))
|
||||
created_date: Mapped[datetime] = mapped_column(default=func.now())
|
||||
last_modified_date: Mapped[datetime] = mapped_column(default=func.now())
|
||||
version: Mapped[int] = mapped_column(default=0)
|
||||
|
||||
|
||||
class BaseVideoMixin:
|
||||
"""
|
||||
Base mixin to provide additional fields for video links.
|
||||
"""
|
||||
|
||||
cloud_link: Mapped[Optional[str]]
|
||||
file_name: Mapped[Optional[str]]
|
||||
path: Mapped[str]
|
||||
review: Mapped[bool]
|
||||
title: Mapped[str]
|
||||
url: Mapped[str]
|
||||
should_download: Mapped[bool]
|
||||
@@ -0,0 +1,102 @@
|
||||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy import ForeignKey
|
||||
from sqlalchemy.orm import Mapped, relationship, mapped_column
|
||||
|
||||
from kontor_robyn.db.models import Base, BaseMixin, BaseVideoMixin
|
||||
|
||||
|
||||
class MediaFile(Base, BaseMixin, BaseVideoMixin):
|
||||
"""
|
||||
MediaFile represents video link.
|
||||
"""
|
||||
|
||||
__tablename__ = "media_file"
|
||||
media_actor_files: Mapped[List["MediaActorFile"]] = relationship(
|
||||
back_populates="media_file"
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"MediaFile({self.id} {self.title} {self.title})"
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.title}({self.id})"
|
||||
|
||||
def update_title(self):
|
||||
"""
|
||||
Update title from url.
|
||||
"""
|
||||
|
||||
|
||||
class MediaActor(Base, BaseMixin):
|
||||
"""
|
||||
MediaActor represents actor for MediaFile
|
||||
"""
|
||||
|
||||
__tablename__ = "media_actor"
|
||||
name: Mapped[str]
|
||||
url: Mapped[Optional[str]] = mapped_column(unique=True)
|
||||
media_actor_files = relationship("MediaActorFile")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"MediaActor({self.id} {self.name} {self.url})"
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.url}({self.id})"
|
||||
|
||||
|
||||
class MediaActorFile(Base, BaseMixin):
|
||||
"""
|
||||
MediaActorFile defines the connection between MediaFile and MediaActor
|
||||
"""
|
||||
|
||||
__tablename__ = "media_actor_file"
|
||||
media_actor_id: Mapped[str] = mapped_column(
|
||||
ForeignKey("media_actor.id"), nullable=False
|
||||
)
|
||||
media_actor: Mapped[MediaActor] = relationship(back_populates="media_actor_files")
|
||||
media_file_id: Mapped[str] = mapped_column(
|
||||
ForeignKey("media_file.id"), nullable=True
|
||||
)
|
||||
media_file: Mapped[MediaFile] = relationship(back_populates="media_actor_files")
|
||||
|
||||
def __repr__(self):
|
||||
return f"MediaActorFile({self.id} {self.media_actor_id} {self.media_file_id})"
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.id} {self.media_actor_id} {self.media_file_id}"
|
||||
|
||||
|
||||
class MediaArticle(Base, BaseMixin):
|
||||
"""
|
||||
MediaArticle represents a link to an article
|
||||
"""
|
||||
|
||||
__tablename__ = "media_article"
|
||||
review: Mapped[bool]
|
||||
title: Mapped[str]
|
||||
url: Mapped[str] = mapped_column(unique=True)
|
||||
|
||||
|
||||
class MediaVideo(Base, BaseMixin):
|
||||
"""
|
||||
MediaFile represents video link.
|
||||
"""
|
||||
|
||||
__tablename__ = "media_video"
|
||||
cloud_link: Mapped[str]
|
||||
file_name: Mapped[str]
|
||||
path: Mapped[str]
|
||||
review: Mapped[bool]
|
||||
title: Mapped[str]
|
||||
url: Mapped[str] = mapped_column(unique=True)
|
||||
should_download: Mapped[bool]
|
||||
|
||||
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})"
|
||||
Reference in New Issue
Block a user