2022-11-15 09:19:08 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
from sqlalchemy import Column, ForeignKey
|
2022-05-04 23:09:46 +00:00
|
|
|
from sqlalchemy.orm import relationship
|
2022-11-15 09:19:08 +00:00
|
|
|
from sqlalchemy.sql.sqltypes import *
|
|
|
|
|
|
|
|
from files.classes import Base
|
2024-05-22 19:26:09 +00:00
|
|
|
from files.helpers.config.awards import *
|
2022-05-04 23:09:46 +00:00
|
|
|
from files.helpers.lazy import lazy
|
|
|
|
|
|
|
|
|
2022-11-15 09:19:08 +00:00
|
|
|
class AwardRelationship(Base):
|
2022-05-04 23:09:46 +00:00
|
|
|
__tablename__ = "award_relationships"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
user_id = Column(Integer, ForeignKey("users.id"))
|
2023-06-07 23:26:32 +00:00
|
|
|
post_id = Column(Integer, ForeignKey("posts.id"))
|
2022-05-04 23:09:46 +00:00
|
|
|
comment_id = Column(Integer, ForeignKey("comments.id"))
|
2024-02-02 23:24:22 +00:00
|
|
|
kind = Column(String)
|
2022-06-25 20:33:51 +00:00
|
|
|
awarded_utc = Column(Integer)
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2024-02-02 23:24:22 +00:00
|
|
|
price_paid = Column(Integer, default = 0)
|
2023-10-04 13:05:43 +00:00
|
|
|
note = Column(String)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-02 06:48:04 +00:00
|
|
|
user = relationship("User", primaryjoin="AwardRelationship.user_id==User.id", back_populates="awards")
|
2023-06-07 23:26:32 +00:00
|
|
|
post = relationship("Post", primaryjoin="AwardRelationship.post_id==Post.id", back_populates="awards")
|
2022-07-02 06:48:04 +00:00
|
|
|
comment = relationship("Comment", 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
|
|
|
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']
|