MarseyWorld/files/classes/award.py

47 lines
1.4 KiB
Python
Raw Normal View History

2022-05-04 23:09:46 +00:00
from sqlalchemy import *
from sqlalchemy.orm import relationship
from files.__main__ import Base
from files.helpers.lazy import lazy
from files.helpers.const import *
2022-09-12 10:19:35 +00:00
import time
2022-05-04 23:09:46 +00:00
class AwardRelationship(Base):
__tablename__ = "award_relationships"
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"))
submission_id = Column(Integer, ForeignKey("submissions.id"))
comment_id = Column(Integer, ForeignKey("comments.id"))
kind = Column(String)
awarded_utc = Column(Integer)
granted_by = Column(Integer, ForeignKey("users.id"))
created_utc = Column(Integer)
2022-05-04 23:09:46 +00:00
user = relationship("User", primaryjoin="AwardRelationship.user_id==User.id", back_populates="awards")
post = relationship("Submission", primaryjoin="AwardRelationship.submission_id==Submission.id", back_populates="awards")
comment = relationship("Comment", primaryjoin="AwardRelationship.comment_id==Comment.id", back_populates="awards")
2022-05-04 23:09:46 +00:00
def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
super().__init__(*args, **kwargs)
def __repr__(self):
return f"<AwardRelationship(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]
else: return HOUSE_AWARDS[self.kind]
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']