forked from MarseyWorld/MarseyWorld
80 lines
2.4 KiB
Python
80 lines
2.4 KiB
Python
import time
|
|
|
|
from sqlalchemy import Column, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql.sqltypes import *
|
|
|
|
from files.classes import Base
|
|
from files.helpers.config.const import *
|
|
from files.helpers.lazy import lazy
|
|
from files.helpers.regex import censor_slurs
|
|
from files.helpers.sorting_and_time import make_age_string
|
|
|
|
class ModAction(Base):
|
|
__tablename__ = "modactions"
|
|
id = Column(Integer, primary_key=True)
|
|
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==ModAction.user_id")
|
|
target_user = relationship("User", primaryjoin="User.id==ModAction.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):
|
|
return f"<{self.__class__.__name__}(id={self.id})>"
|
|
|
|
@property
|
|
@lazy
|
|
def age_string(self):
|
|
return make_age_string(self.created_utc)
|
|
|
|
@property
|
|
def note(self):
|
|
if self.kind=="ban_user":
|
|
if self.target_post: return f'for <a href="{self.target_post.permalink}">post</a>'
|
|
elif self.target_comment_id: return f'for <a href="/comment/{self.target_comment_id}">comment</a>'
|
|
else: return self._note
|
|
else:
|
|
return self._note or ""
|
|
|
|
@property
|
|
@lazy
|
|
def string(self):
|
|
output = MODACTION_TYPES[self.kind]["str"].format(self=self)
|
|
if self.note: output += f" <i>({self.note})</i>"
|
|
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)
|
|
elif self.target_comment_id: return f'<a href="/comment/{self.target_comment_id}#context">comment</a>'
|
|
|
|
@property
|
|
@lazy
|
|
def icon(self):
|
|
return MODACTION_TYPES[self.kind]['icon']
|
|
|
|
@property
|
|
@lazy
|
|
def color(self):
|
|
return MODACTION_TYPES[self.kind]['color']
|
|
|
|
@property
|
|
@lazy
|
|
def permalink(self):
|
|
return f"{SITE_FULL}/log/{self.id}"
|
|
|
|
from files.helpers.config.modaction_types import MODACTION_TYPES, MODACTION_TYPES_FILTERED
|