MarseyWorld/files/classes/votes.py

58 lines
1.5 KiB
Python
Raw Normal View History

2022-05-04 23:09:46 +00:00
from flask import *
from sqlalchemy import *
from sqlalchemy.orm import relationship
from files.__main__ import Base
from files.helpers.lazy import lazy
import time
class Vote(Base):
__tablename__ = "votes"
submission_id = Column(Integer, ForeignKey("submissions.id"), primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
vote_type = Column(Integer)
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
real = Column(Boolean, default=True)
2022-09-19 19:24:16 +00:00
created_utc = Column(Integer, default=int(time.time()))
2022-05-04 23:09:46 +00:00
2022-07-03 06:16:26 +00:00
user = relationship("User")
2022-05-04 23:09:46 +00:00
def __repr__(self):
return f"<Vote(id={self.id})>"
@property
@lazy
2022-07-11 17:33:26 +00:00
def json(self):
return {"user_id": self.user_id,
2022-05-04 23:09:46 +00:00
"submission_id":self.submission_id,
2022-07-11 17:33:26 +00:00
"vote_type":self.vote_type,
"user":self.user.json,
"post":self.post.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)
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
real = Column(Boolean, default=True)
2022-09-19 19:24:16 +00:00
created_utc = Column(Integer, default=int(time.time()))
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
def __repr__(self):
return f"<CommentVote(id={self.id})>"
@property
@lazy
def json(self):
2022-07-11 17:33:26 +00:00
return {"user_id": self.user_id,
"submission_id":self.submission_id,
"vote_type":self.vote_type,
"user":self.user.json,
"comment":self.comment.json
}