Files
core/orm/reaction.py

70 lines
2.3 KiB
Python
Raw Normal View History

2023-11-22 19:38:39 +03:00
import time
2022-09-19 16:50:43 +03:00
from enum import Enum as Enumeration
2023-11-22 19:38:39 +03:00
2025-07-31 18:55:59 +03:00
from sqlalchemy import ForeignKey, Index, Integer, String
from sqlalchemy.orm import Mapped, mapped_column
2023-11-22 19:38:39 +03:00
2025-07-31 18:55:59 +03:00
from auth.orm import Author
2025-07-25 01:04:15 +03:00
from orm.base import BaseModel as Base
2022-09-19 16:50:43 +03:00
class ReactionKind(Enumeration):
2023-11-27 19:03:47 +03:00
# TYPE = <reaction index> # rating diff
2025-07-02 22:30:21 +03:00
# editor specials
2024-04-17 18:32:23 +03:00
AGREE = "AGREE" # +1
DISAGREE = "DISAGREE" # -1
2025-07-02 22:30:21 +03:00
# coauthor specials
ASK = "ASK" # 0
PROPOSE = "PROPOSE" # 0
# generic internal reactions
2024-04-17 18:32:23 +03:00
ACCEPT = "ACCEPT" # +1
REJECT = "REJECT" # -1
2023-11-27 19:03:47 +03:00
2025-07-02 22:30:21 +03:00
# experts speacials
2024-04-17 18:32:23 +03:00
PROOF = "PROOF" # +1
DISPROOF = "DISPROOF" # -1
2024-04-09 14:03:50 +03:00
2025-07-02 22:30:21 +03:00
# comment and quote
QUOTE = "QUOTE" # 0
COMMENT = "COMMENT" # 0
# generic rating
2024-04-17 18:32:23 +03:00
LIKE = "LIKE" # +1
DISLIKE = "DISLIKE" # -1
2025-07-02 22:30:21 +03:00
# credit artist or researcher
CREDIT = "CREDIT" # +1
SILENT = "SILENT" # 0
REACTION_KINDS = ReactionKind.__members__.keys()
2022-09-03 13:50:14 +03:00
class Reaction(Base):
2024-04-17 18:32:23 +03:00
__tablename__ = "reaction"
2023-10-23 17:47:11 +03:00
2025-07-31 18:55:59 +03:00
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
body: Mapped[str] = mapped_column(String, default="", comment="Reaction Body")
created_at: Mapped[int] = mapped_column(Integer, nullable=False, default=lambda: int(time.time()), index=True)
updated_at: Mapped[int | None] = mapped_column(Integer, nullable=True, comment="Updated at", index=True)
deleted_at: Mapped[int | None] = mapped_column(Integer, nullable=True, comment="Deleted at", index=True)
deleted_by: Mapped[int | None] = mapped_column(ForeignKey(Author.id), nullable=True)
reply_to: Mapped[int | None] = mapped_column(ForeignKey("reaction.id"), nullable=True)
quote: Mapped[str | None] = mapped_column(String, nullable=True, comment="Original quoted text")
shout: Mapped[int] = mapped_column(ForeignKey("shout.id"), nullable=False, index=True)
created_by: Mapped[int] = mapped_column(ForeignKey(Author.id), nullable=False)
kind: Mapped[str] = mapped_column(String, nullable=False, index=True)
oid: Mapped[str | None] = mapped_column(String)
__table_args__ = (
Index("idx_reaction_created_at", "created_at"),
Index("idx_reaction_created_by", "created_by"),
Index("idx_reaction_shout", "shout"),
Index("idx_reaction_kind", "kind"),
{"extend_existing": True},
)