2022-05-04 23:09:46 +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-08-21 17:08:48 +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-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
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"))
|
2023-06-07 23:26:32 +00:00
|
|
|
target_post_id = Column(Integer, ForeignKey("posts.id"))
|
2022-05-04 23:09:46 +00:00
|
|
|
target_comment_id = Column(Integer, ForeignKey("comments.id"))
|
2023-08-23 21:57:39 +00:00
|
|
|
_note = Column(String)
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-02 06:48:04 +00:00
|
|
|
user = relationship("User", primaryjoin="User.id==ModAction.user_id")
|
|
|
|
target_user = relationship("User", primaryjoin="User.id==ModAction.target_user_id")
|
2023-06-07 23:26:32 +00:00
|
|
|
target_post = relationship("Post")
|
2023-08-05 14:08:14 +00:00
|
|
|
target_comment = relationship("Comment")
|
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-05-04 23:09:46 +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 age_string(self):
|
2022-10-15 18:11:43 +00:00
|
|
|
return make_age_string(self.created_utc)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def note(self):
|
2023-08-05 14:12:25 +00:00
|
|
|
if self.kind == "ban_user":
|
|
|
|
if self.target_post_id:
|
|
|
|
return f'for <a href="{self.target_post.permalink}">post</a>'
|
|
|
|
elif self.target_comment_id:
|
|
|
|
return f'for <a href="{self.target_comment.permalink}">comment</a>'
|
|
|
|
else:
|
|
|
|
return self._note
|
2022-05-04 23:09:46 +00:00
|
|
|
else:
|
|
|
|
return self._note or ""
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def string(self):
|
2022-12-11 23:44:34 +00:00
|
|
|
output = MODACTION_TYPES[self.kind]["str"].format(self=self)
|
2022-05-04 23:09:46 +00:00
|
|
|
if self.note: output += f" <i>({self.note})</i>"
|
|
|
|
return output
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def target_link(self):
|
2023-08-05 14:12:25 +00:00
|
|
|
if self.target_user_id:
|
|
|
|
return f'<a href="{self.target_user.url}">@{self.target_user.username}</a>'
|
|
|
|
elif self.target_post_id:
|
2022-08-21 17:08:48 +00:00
|
|
|
return censor_slurs(f'<a href="{self.target_post.permalink}">{self.target_post.title_html}</a>', None)
|
2023-08-05 14:12:25 +00:00
|
|
|
elif self.target_comment_id:
|
|
|
|
return f'<a href="{self.target_comment.permalink}">comment</a>'
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def icon(self):
|
2022-12-11 23:44:34 +00:00
|
|
|
return MODACTION_TYPES[self.kind]['icon']
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def color(self):
|
2022-12-11 23:44:34 +00:00
|
|
|
return MODACTION_TYPES[self.kind]['color']
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def permalink(self):
|
2022-09-29 12:43:14 +00:00
|
|
|
return f"{SITE_FULL}/log/{self.id}"
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-12-11 23:44:34 +00:00
|
|
|
from files.helpers.config.modaction_types import MODACTION_TYPES, MODACTION_TYPES_FILTERED
|