2022-11-15 09:19:08 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
from sqlalchemy import Column, ForeignKey
|
2022-05-04 23:09:46 +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-05-04 23:09:46 +00:00
|
|
|
from files.helpers.lazy import lazy
|
|
|
|
|
|
|
|
class Vote(Base):
|
|
|
|
__tablename__ = "votes"
|
|
|
|
|
2023-06-07 23:26:32 +00:00
|
|
|
post_id = Column(Integer, ForeignKey("posts.id"), primary_key=True)
|
2022-05-04 23:09:46 +00:00
|
|
|
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
|
|
|
|
vote_type = Column(Integer)
|
|
|
|
real = Column(Boolean, default=True)
|
2022-10-23 22:23:51 +00:00
|
|
|
coins = Column(Integer, default=1, nullable=False)
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-03 06:16:26 +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-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}, vote_type={self.vote_type})>"
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
2022-07-11 17:33:26 +00:00
|
|
|
def json(self):
|
2022-11-18 20:33:07 +00:00
|
|
|
return {
|
|
|
|
"user_id": self.user_id,
|
2023-06-07 23:26:32 +00:00
|
|
|
"post_id": self.post_id,
|
2022-11-18 20:33:07 +00:00
|
|
|
"vote_type": self.vote_type,
|
|
|
|
"user": self.user.json,
|
|
|
|
}
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
class CommentVote(Base):
|
|
|
|
|
|
|
|
__tablename__ = "commentvotes"
|
|
|
|
|
|
|
|
comment_id = Column(Integer, ForeignKey("comments.id"), primary_key=True)
|
|
|
|
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
|
|
|
|
vote_type = Column(Integer)
|
|
|
|
real = Column(Boolean, default=True)
|
2022-10-23 22:23:51 +00:00
|
|
|
coins = Column(Integer, default=1, nullable=False)
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-03 06:12:53 +00:00
|
|
|
user = relationship("User")
|
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}, vote_type={self.vote_type})>"
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def json(self):
|
2022-11-18 20:33:07 +00:00
|
|
|
return {
|
|
|
|
"user_id": self.user_id,
|
2023-06-07 23:26:32 +00:00
|
|
|
"post_id": self.post_id,
|
2022-11-18 20:33:07 +00:00
|
|
|
"vote_type": self.vote_type,
|
|
|
|
"user": self.user.json,
|
|
|
|
}
|