core/orm/shout.py

86 lines
2.9 KiB
Python
Raw Normal View History

2023-11-03 10:10:22 +00:00
import time
2023-10-23 14:47:11 +00:00
from enum import Enum as Enumeration
2023-11-22 16:38:39 +00:00
from sqlalchemy import JSON, Boolean, Column, Enum, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from orm.author import Author
2023-10-23 14:47:11 +00:00
from orm.community import Community
from orm.reaction import Reaction
2022-09-19 13:50:43 +00:00
from orm.topic import Topic
2023-11-22 16:38:39 +00:00
from services.db import Base
2022-09-19 13:50:43 +00:00
class ShoutTopic(Base):
__tablename__ = "shout_topic"
id = None # type: ignore
2022-11-30 06:27:12 +00:00
shout = Column(ForeignKey("shout.id"), primary_key=True, index=True)
topic = Column(ForeignKey("topic.id"), primary_key=True, index=True)
2021-09-24 14:39:37 +00:00
class ShoutReactionsFollower(Base):
__tablename__ = "shout_reactions_followers"
2022-09-03 10:50:14 +00:00
id = None # type: ignore
2023-10-23 14:47:11 +00:00
follower = Column(ForeignKey("author.id"), primary_key=True, index=True)
2022-11-30 06:27:12 +00:00
shout = Column(ForeignKey("shout.id"), primary_key=True, index=True)
2022-09-03 10:50:14 +00:00
auto = Column(Boolean, nullable=False, default=False)
2023-11-03 10:10:22 +00:00
created_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
deleted_at = Column(Integer, nullable=True)
2022-09-03 10:50:14 +00:00
2022-06-21 12:21:02 +00:00
2021-08-28 10:13:50 +00:00
class ShoutAuthor(Base):
__tablename__ = "shout_author"
2022-09-03 10:50:14 +00:00
id = None # type: ignore
2022-11-30 06:27:12 +00:00
shout = Column(ForeignKey("shout.id"), primary_key=True, index=True)
2023-10-23 14:47:11 +00:00
author = Column(ForeignKey("author.id"), primary_key=True, index=True)
2022-09-03 10:50:14 +00:00
caption = Column(String, nullable=True, default="")
2023-10-25 17:25:53 +00:00
class ShoutCommunity(Base):
2023-10-23 14:47:11 +00:00
__tablename__ = "shout_community"
id = None # type: ignore
shout = Column(ForeignKey("shout.id"), primary_key=True, index=True)
community = Column(ForeignKey("community.id"), primary_key=True, index=True)
class ShoutVisibility(Enumeration):
AUTHORS = 0
COMMUNITY = 1
PUBLIC = 2
2022-09-03 10:50:14 +00:00
class Shout(Base):
__tablename__ = "shout"
2023-11-03 10:10:22 +00:00
created_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
updated_at = Column(Integer, nullable=True)
published_at = Column(Integer, nullable=True)
deleted_at = Column(Integer, nullable=True)
2023-11-28 07:53:48 +00:00
2023-11-03 10:10:22 +00:00
deleted_by = Column(ForeignKey("author.id"), nullable=True)
2023-10-23 14:47:11 +00:00
body = Column(String, nullable=False, comment="Body")
2022-11-10 05:40:32 +00:00
slug = Column(String, unique=True)
cover = Column(String, nullable=True, comment="Cover image url")
lead = Column(String, nullable=True)
2023-08-21 11:30:18 +00:00
description = Column(String, nullable=True)
2022-09-03 10:50:14 +00:00
title = Column(String, nullable=True)
subtitle = Column(String, nullable=True)
layout = Column(String, nullable=True)
2023-02-17 14:30:38 +00:00
media = Column(JSON, nullable=True)
2023-10-23 14:47:11 +00:00
2023-11-22 16:38:39 +00:00
authors = relationship(lambda: Author, secondary="shout_author")
topics = relationship(lambda: Topic, secondary="shout_topic")
communities = relationship(lambda: Community, secondary="shout_community")
2023-10-23 14:47:11 +00:00
reactions = relationship(lambda: Reaction)
2023-02-17 14:30:38 +00:00
2023-10-23 14:47:11 +00:00
visibility = Column(Enum(ShoutVisibility), default=ShoutVisibility.AUTHORS)
2023-02-17 14:30:38 +00:00
2023-10-05 18:46:18 +00:00
lang = Column(String, nullable=False, default="ru", comment="Language")
2023-11-03 10:10:22 +00:00
version_of = Column(ForeignKey("shout.id"), nullable=True)
2022-11-13 04:07:52 +00:00
oid = Column(String, nullable=True)