2022-11-15 09:19:08 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
from sqlalchemy import Column, ForeignKey
|
2022-07-02 06:48:04 +00:00
|
|
|
from sqlalchemy.orm import relationship
|
2022-11-15 09:19:08 +00:00
|
|
|
from sqlalchemy.sql.sqltypes import *
|
|
|
|
|
|
|
|
from files.classes import Base
|
2022-07-02 06:48:04 +00:00
|
|
|
from files.helpers.lazy import lazy
|
|
|
|
|
2023-06-07 23:26:32 +00:00
|
|
|
class PostOption(Base):
|
|
|
|
__tablename__ = "post_options"
|
2022-07-02 06:48:04 +00:00
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
2023-06-07 23:26:32 +00:00
|
|
|
parent_id = Column(Integer, ForeignKey("posts.id"))
|
2022-07-02 06:48:04 +00:00
|
|
|
body_html = Column(Text)
|
2022-08-26 21:53:17 +00:00
|
|
|
exclusive = Column(Integer)
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2022-07-02 06:48:04 +00:00
|
|
|
|
2023-06-07 23:26:32 +00:00
|
|
|
votes = relationship("PostOptionVote")
|
|
|
|
parent = relationship("Post", back_populates="options")
|
2022-07-02 06:48:04 +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-07-02 06:48:04 +00:00
|
|
|
def __repr__(self):
|
2022-11-29 21:02:38 +00:00
|
|
|
return f"<{self.__class__.__name__}(id={self.id})>"
|
2022-07-02 06:48:04 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def upvotes(self):
|
|
|
|
return len(self.votes)
|
|
|
|
|
|
|
|
@lazy
|
|
|
|
def voted(self, v):
|
2022-07-02 09:47:35 +00:00
|
|
|
if not v: return False
|
2022-07-02 06:48:04 +00:00
|
|
|
return v.id in [x.user_id for x in self.votes]
|
|
|
|
|
2023-06-07 23:26:32 +00:00
|
|
|
class PostOptionVote(Base):
|
2022-07-02 06:48:04 +00:00
|
|
|
|
2023-06-07 23:26:32 +00:00
|
|
|
__tablename__ = "post_option_votes"
|
2022-07-02 06:48:04 +00:00
|
|
|
|
2023-06-07 23:26:32 +00:00
|
|
|
option_id = Column(Integer, ForeignKey("post_options.id"), primary_key=True)
|
2022-07-02 06:48:04 +00:00
|
|
|
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2023-06-07 23:26:32 +00:00
|
|
|
post_id = Column(Integer, ForeignKey("posts.id"))
|
2022-07-02 06:48:04 +00:00
|
|
|
|
|
|
|
user = relationship("User")
|
|
|
|
|
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-07-02 06:48:04 +00:00
|
|
|
def __repr__(self):
|
2022-11-29 21:02:38 +00:00
|
|
|
return f"<{self.__class__.__name__}(option_id={self.option_id}, user_id={self.user_id})>"
|
2022-07-02 06:48:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CommentOption(Base):
|
|
|
|
|
|
|
|
__tablename__ = "comment_options"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
2023-02-28 22:09:16 +00:00
|
|
|
parent_id = Column(Integer, ForeignKey("comments.id"))
|
2022-07-02 06:48:04 +00:00
|
|
|
body_html = Column(Text)
|
2022-08-26 21:53:17 +00:00
|
|
|
exclusive = Column(Integer)
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2022-07-02 06:48:04 +00:00
|
|
|
|
|
|
|
votes = relationship("CommentOptionVote")
|
2023-03-12 17:36:35 +00:00
|
|
|
parent = relationship("Comment", back_populates="options")
|
2022-07-02 06:48:04 +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-07-02 06:48:04 +00:00
|
|
|
def __repr__(self):
|
2022-11-29 21:02:38 +00:00
|
|
|
return f"<{self.__class__.__name__}(id={self.id})>"
|
2022-07-02 06:48:04 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def upvotes(self):
|
|
|
|
return len(self.votes)
|
|
|
|
|
|
|
|
@lazy
|
|
|
|
def voted(self, v):
|
2022-07-02 09:47:49 +00:00
|
|
|
if not v: return False
|
2022-07-02 06:48:04 +00:00
|
|
|
return v.id in [x.user_id for x in self.votes]
|
|
|
|
|
|
|
|
class CommentOptionVote(Base):
|
|
|
|
|
|
|
|
__tablename__ = "comment_option_votes"
|
|
|
|
|
|
|
|
option_id = Column(Integer, ForeignKey("comment_options.id"), primary_key=True)
|
|
|
|
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2022-07-02 06:48:04 +00:00
|
|
|
comment_id = Column(Integer, ForeignKey("comments.id"))
|
|
|
|
|
|
|
|
user = relationship("User")
|
|
|
|
|
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-07-02 06:48:04 +00:00
|
|
|
def __repr__(self):
|
2022-11-29 21:02:38 +00:00
|
|
|
return f"<{self.__class__.__name__}(option_id={self.option_id}, user_id={self.user_id})>"
|