2022-11-15 09:19:08 +00:00
|
|
|
import time
|
2024-02-15 13:17:23 +00:00
|
|
|
from typing import Optional, TYPE_CHECKING
|
2022-11-15 09:19:08 +00:00
|
|
|
|
2024-02-15 13:17:23 +00:00
|
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
2022-11-15 09:19:08 +00:00
|
|
|
from sqlalchemy.sql.sqltypes import *
|
|
|
|
|
|
|
|
from files.classes import Base
|
2022-12-11 23:44:34 +00:00
|
|
|
from files.helpers.config.awards import AWARDS, HOUSE_AWARDS
|
2022-05-04 23:09:46 +00:00
|
|
|
from files.helpers.lazy import lazy
|
2024-02-15 21:50:18 +00:00
|
|
|
from files.helpers.types import comment_id_fk, int_pk, post_id_fk, user_id_fk
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-02-15 13:17:23 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from files.classes import Comment, Post, User
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-11-15 09:19:08 +00:00
|
|
|
class AwardRelationship(Base):
|
2022-05-04 23:09:46 +00:00
|
|
|
__tablename__ = "award_relationships"
|
|
|
|
|
2024-02-15 21:50:18 +00:00
|
|
|
id: Mapped[int_pk]
|
|
|
|
user_id: Mapped[user_id_fk]
|
|
|
|
post_id: Mapped[Optional[post_id_fk]]
|
|
|
|
comment_id: Mapped[Optional[comment_id_fk]]
|
2024-02-15 13:17:23 +00:00
|
|
|
kind: Mapped[str]
|
2024-02-15 13:17:23 +00:00
|
|
|
awarded_utc: Mapped[Optional[int]]
|
|
|
|
created_utc: Mapped[Optional[int]]
|
2024-02-15 13:17:23 +00:00
|
|
|
price_paid: Mapped[int] = mapped_column(default = 0)
|
2024-02-15 13:17:23 +00:00
|
|
|
note: Mapped[Optional[str]]
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-02-15 13:17:23 +00:00
|
|
|
user: Mapped["User"] = relationship(primaryjoin="AwardRelationship.user_id==User.id", back_populates="awards")
|
|
|
|
post: Mapped["Post"] = relationship(primaryjoin="AwardRelationship.post_id==Post.id", back_populates="awards")
|
|
|
|
comment: Mapped["Comment"] = relationship(primaryjoin="AwardRelationship.comment_id==Comment.id", back_populates="awards")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-09-19 20:40:33 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2022-07-02 06:48:04 +00:00
|
|
|
def __repr__(self):
|
2022-11-29 21:02:38 +00:00
|
|
|
return f"<{self.__class__.__name__}(id={self.id})>"
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def type(self):
|
2022-08-30 01:13:43 +00:00
|
|
|
if self.kind in AWARDS: return AWARDS[self.kind]
|
2022-11-28 05:22:57 +00:00
|
|
|
elif self.kind in HOUSE_AWARDS: return HOUSE_AWARDS[self.kind]
|
|
|
|
else: return AWARDS["fallback"]
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def title(self):
|
|
|
|
return self.type['title']
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def class_list(self):
|
|
|
|
return self.type['icon']+' '+self.type['color']
|