2022-09-29 09:39:37 +00:00
|
|
|
import time
|
2022-11-15 09:19:08 +00:00
|
|
|
|
|
|
|
from sqlalchemy import Column, ForeignKey
|
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from sqlalchemy.sql.sqltypes import *
|
|
|
|
|
|
|
|
from files.classes import Base
|
2022-12-11 23:44:34 +00:00
|
|
|
from files.helpers.config.const import *
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.helpers.lazy import lazy
|
2022-09-29 09:39:37 +00:00
|
|
|
from files.helpers.regex import censor_slurs
|
2022-10-15 18:11:43 +00:00
|
|
|
from files.helpers.sorting_and_time import make_age_string
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
class SubAction(Base):
|
|
|
|
__tablename__ = "subactions"
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
sub = Column(String, ForeignKey("subs.name"))
|
|
|
|
user_id = Column(Integer, ForeignKey("users.id"))
|
|
|
|
kind = Column(String)
|
|
|
|
target_user_id = Column(Integer, ForeignKey("users.id"))
|
|
|
|
target_submission_id = Column(Integer, ForeignKey("submissions.id"))
|
|
|
|
target_comment_id = Column(Integer, ForeignKey("comments.id"))
|
|
|
|
_note=Column(String)
|
|
|
|
created_utc = Column(Integer)
|
|
|
|
|
|
|
|
user = relationship("User", primaryjoin="User.id==SubAction.user_id")
|
|
|
|
target_user = relationship("User", primaryjoin="User.id==SubAction.target_user_id")
|
|
|
|
target_post = relationship("Submission")
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def __repr__(self):
|
2022-11-29 21:02:38 +00:00
|
|
|
return f"<{self.__class__.__name__}(id={self.id})>"
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def age_string(self):
|
2022-10-15 18:11:43 +00:00
|
|
|
return make_age_string(self.created_utc)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def string(self):
|
2022-12-11 23:44:34 +00:00
|
|
|
output = SUBACTION_TYPES[self.kind]["str"].format(self=self)
|
2022-09-29 10:18:27 +00:00
|
|
|
if self._note: output += f" <i>({self._note})</i>"
|
2022-09-29 09:39:37 +00:00
|
|
|
return output
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def target_link(self):
|
|
|
|
if self.target_user: return f'<a href="{self.target_user.url}">{self.target_user.username}</a>'
|
|
|
|
elif self.target_post:
|
|
|
|
return censor_slurs(f'<a href="{self.target_post.permalink}">{self.target_post.title_html}</a>', None)
|
2022-12-18 14:48:48 +00:00
|
|
|
elif self.target_comment_id: return f'<a href="/comment/{self.target_comment_id}#context">comment</a>'
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def icon(self):
|
2022-12-11 23:44:34 +00:00
|
|
|
return SUBACTION_TYPES[self.kind]['icon']
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def color(self):
|
2022-12-11 23:44:34 +00:00
|
|
|
return SUBACTION_TYPES[self.kind]['color']
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def permalink(self):
|
2022-09-29 12:43:14 +00:00
|
|
|
return f"{SITE_FULL}/h/{self.sub}/log/{self.id}"
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2022-12-11 23:44:34 +00:00
|
|
|
from files.helpers.config.subaction_types import SUBACTION_TYPES
|