MarseyWorld/files/classes/votes.py

58 lines
1.5 KiB
Python

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)
created_utc = Column(Integer, default=int(time.time()))
user = relationship("User")
def __repr__(self):
return f"<Vote(id={self.id})>"
@property
@lazy
def json(self):
return {"user_id": self.user_id,
"submission_id":self.submission_id,
"vote_type":self.vote_type,
"user":self.user.json,
"post":self.post.json
}
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)
created_utc = Column(Integer, default=int(time.time()))
user = relationship("User")
def __repr__(self):
return f"<CommentVote(id={self.id})>"
@property
@lazy
def json(self):
return {"user_id": self.user_id,
"submission_id":self.submission_id,
"vote_type":self.vote_type,
"user":self.user.json,
"comment":self.comment.json
}