hfg
This commit is contained in:
parent
4d9815210c
commit
1c84399650
5 changed files with 29 additions and 19 deletions
|
@ -18,4 +18,5 @@ from files.__main__ import app
|
||||||
from .mod_logs import *
|
from .mod_logs import *
|
||||||
from .award import *
|
from .award import *
|
||||||
from .marsey import *
|
from .marsey import *
|
||||||
from .sub_block import *
|
from .sub_block import *
|
||||||
|
from .saves import *
|
20
files/classes/saves.py
Normal file
20
files/classes/saves.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
from sqlalchemy import *
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
from files.__main__ import Base
|
||||||
|
|
||||||
|
|
||||||
|
class SaveRelationship(Base):
|
||||||
|
|
||||||
|
__tablename__="save_relationship"
|
||||||
|
|
||||||
|
user_id=Column(Integer, primary_key=True)
|
||||||
|
submission_id=Column(Integer, primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class CommentSaveRelationship(Base):
|
||||||
|
|
||||||
|
__tablename__="comment_save_relationship"
|
||||||
|
|
||||||
|
user_id=Column(Integer, primary_key=True)
|
||||||
|
comment_id=Column(Integer, primary_key=True)
|
|
@ -479,14 +479,4 @@ class Submission(Base):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def active_flags(self): return self.flags.count()
|
def active_flags(self): return self.flags.count()
|
||||||
|
|
||||||
|
|
||||||
class SaveRelationship(Base):
|
|
||||||
|
|
||||||
__tablename__="save_relationship"
|
|
||||||
|
|
||||||
id=Column(Integer, primary_key=True)
|
|
||||||
user_id=Column(Integer)
|
|
||||||
submission_id=Column(Integer)
|
|
||||||
comment_id=Column(Integer)
|
|
|
@ -5,7 +5,7 @@ from files.helpers.discord import remove_user
|
||||||
from files.helpers.images import *
|
from files.helpers.images import *
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
from .alts import Alt
|
from .alts import Alt
|
||||||
from .submission import SaveRelationship
|
from .saves import *
|
||||||
from .comment import Notification
|
from .comment import Notification
|
||||||
from .award import AwardRelationship
|
from .award import AwardRelationship
|
||||||
from .subscriptions import *
|
from .subscriptions import *
|
||||||
|
@ -581,7 +581,7 @@ class User(Base):
|
||||||
@lazy
|
@lazy
|
||||||
def saved_idlist(self, page=1):
|
def saved_idlist(self, page=1):
|
||||||
|
|
||||||
saved = [x[0] for x in g.db.query(SaveRelationship.submission_id).filter(SaveRelationship.user_id == self.id).all()]
|
saved = [x[0] for x in g.db.query(SaveRelationship.submission_id).filter_by(user_id=self.id).all()]
|
||||||
posts = g.db.query(Submission.id).filter(Submission.id.in_(saved), Submission.is_banned == False, Submission.deleted_utc == 0)
|
posts = g.db.query(Submission.id).filter(Submission.id.in_(saved), Submission.is_banned == False, Submission.deleted_utc == 0)
|
||||||
|
|
||||||
if self.admin_level == 0:
|
if self.admin_level == 0:
|
||||||
|
@ -602,8 +602,7 @@ class User(Base):
|
||||||
@lazy
|
@lazy
|
||||||
def saved_comment_idlist(self, page=1):
|
def saved_comment_idlist(self, page=1):
|
||||||
|
|
||||||
try: saved = [x[0] for x in g.db.query(SaveRelationship.comment_id).filter(SaveRelationship.user_id == self.id).all()]
|
saved = [x[0] for x in g.db.query(CommentSaveRelationship.comment_id).filter_by(user_id=self.id).all()]
|
||||||
except: return []
|
|
||||||
comments = g.db.query(Comment.id).filter(Comment.id.in_(saved), Comment.is_banned == False, Comment.deleted_utc == 0)
|
comments = g.db.query(Comment.id).filter(Comment.id.in_(saved), Comment.is_banned == False, Comment.deleted_utc == 0)
|
||||||
|
|
||||||
if self.admin_level == 0:
|
if self.admin_level == 0:
|
||||||
|
|
|
@ -1003,10 +1003,10 @@ def save_comment(cid, v):
|
||||||
|
|
||||||
comment=get_comment(cid)
|
comment=get_comment(cid)
|
||||||
|
|
||||||
save=g.db.query(SaveRelationship).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
|
save=g.db.query(CommentSaveRelationship).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
|
||||||
|
|
||||||
if not save:
|
if not save:
|
||||||
new_save=SaveRelationship(user_id=v.id, comment_id=comment.id)
|
new_save=CommentSaveRelationship(user_id=v.id, comment_id=comment.id)
|
||||||
g.db.add(new_save)
|
g.db.add(new_save)
|
||||||
|
|
||||||
try: g.db.commit()
|
try: g.db.commit()
|
||||||
|
@ -1021,7 +1021,7 @@ def unsave_comment(cid, v):
|
||||||
|
|
||||||
comment=get_comment(cid)
|
comment=get_comment(cid)
|
||||||
|
|
||||||
save=g.db.query(SaveRelationship).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
|
save=g.db.query(CommentSaveRelationship).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
|
||||||
|
|
||||||
if save:
|
if save:
|
||||||
g.db.delete(save)
|
g.db.delete(save)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue