rDrama/files/classes/award.py

89 lines
2.2 KiB
Python
Raw Normal View History

2021-07-25 00:04:07 +00:00
from sqlalchemy import *
from sqlalchemy.orm import relationship
2021-08-04 15:35:10 +00:00
from files.__main__ import Base
2021-08-22 18:25:50 +00:00
from os import environ
2021-07-25 00:04:07 +00:00
2021-08-22 18:25:50 +00:00
site_name = environ.get("SITE_NAME").strip()
2021-08-22 18:26:19 +00:00
if site_name == "Drama":
2021-08-22 18:25:50 +00:00
AWARDS = {
"ban": {
"kind": "ban",
"title": "One-Day Ban",
"description": "Ban the author for a day.",
"icon": "fas fa-gavel",
"color": "text-danger"
},
"shit": {
"kind": "shit",
2021-09-08 03:19:52 +00:00
"title": "Shit",
2021-08-22 18:25:50 +00:00
"description": "Let OP know how much their post sucks ass. Flies will swarm their idiotic post. (flies only work on posts lol!!)",
"icon": "fas fa-poop",
"color": "text-black-50"
2021-08-22 20:11:48 +00:00
},
2021-09-08 03:19:52 +00:00
"stars": {
"kind": "stars",
"title": "Stars",
2021-09-08 03:22:52 +00:00
"description": "A positive award because we need a positive award. Puts annoying stars in the post.",
2021-08-22 20:11:48 +00:00
"icon": "fas fa-sparkles",
"color": "text-warning"
2021-08-22 18:25:50 +00:00
}
}
else:
AWARDS = {
"shit": {
"kind": "shit",
2021-09-08 03:19:52 +00:00
"title": "shit",
2021-08-22 18:25:50 +00:00
"description": "Let OP know how much their post sucks ass. Flies will swarm their idiotic post. (flies only work on posts lol!!)",
"icon": "fas fa-poop",
"color": "text-black-50"
2021-08-23 17:53:50 +00:00
},
2021-09-08 03:19:52 +00:00
"stars": {
"kind": "stars",
"title": "Stars",
2021-09-08 03:22:52 +00:00
"description": "A positive award because we need a positive award. Puts annoying stars in the post.",
2021-08-23 17:53:50 +00:00
"icon": "fas fa-sparkles",
"color": "text-warning"
2021-08-22 18:25:50 +00:00
}
2021-07-25 00:04:07 +00:00
}
class AwardRelationship(Base):
__tablename__ = "award_relationships"
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"))
2021-07-27 11:06:43 +00:00
submission_id = Column(Integer, ForeignKey("submissions.id"), default=None)
comment_id = Column(Integer, ForeignKey("comments.id"), default=None)
2021-07-25 00:04:07 +00:00
kind = Column(String(20))
user = relationship("User", primaryjoin="AwardRelationship.user_id==User.id", lazy="joined")
post = relationship(
"Submission",
primaryjoin="AwardRelationship.submission_id==Submission.id",
lazy="joined"
)
comment = relationship(
"Comment",
primaryjoin="AwardRelationship.comment_id==Comment.id",
lazy="joined"
)
2021-07-27 11:06:43 +00:00
@property
def given(self):
return bool(self.submission_id) or bool(self.comment_id)
2021-07-25 00:04:07 +00:00
@property
def type(self):
return AWARDS[self.kind]
2021-07-27 11:06:43 +00:00
@property
def title(self):
return self.type['title']
@property
def class_list(self):
return self.type['icon']+' '+self.type['color']