|
|
@ -4,7 +4,7 @@ import os
|
|
|
|
from datetime import datetime
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
from flask import current_app, url_for
|
|
|
|
from flask import current_app, url_for
|
|
|
|
from flask_login import UserMixin, login_user, logout_user
|
|
|
|
from flask_login import UserMixin, login_user, logout_user, current_user
|
|
|
|
from PIL import Image
|
|
|
|
from PIL import Image
|
|
|
|
from sqlalchemy_utc import UtcDateTime, utcnow
|
|
|
|
from sqlalchemy_utc import UtcDateTime, utcnow
|
|
|
|
from werkzeug.security import check_password_hash, generate_password_hash
|
|
|
|
from werkzeug.security import check_password_hash, generate_password_hash
|
|
|
@ -61,6 +61,10 @@ class User(UserMixin, TimestampMixin, db.Model):
|
|
|
|
user_status = db.Column(db.Enum(USER_STATUS), default=USER_STATUS.active, nullable=False)
|
|
|
|
user_status = db.Column(db.Enum(USER_STATUS), default=USER_STATUS.active, nullable=False)
|
|
|
|
last_login = db.Column(UtcDateTime)
|
|
|
|
last_login = db.Column(UtcDateTime)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ban_status = None
|
|
|
|
|
|
|
|
ban_until = None
|
|
|
|
|
|
|
|
ban_reason = None
|
|
|
|
|
|
|
|
|
|
|
|
#authored_posts = db.relationship('Post', back_populates='author')
|
|
|
|
#authored_posts = db.relationship('Post', back_populates='author')
|
|
|
|
#approved_posts = db.relationship('Post', back_populates='approver')
|
|
|
|
#approved_posts = db.relationship('Post', back_populates='approver')
|
|
|
|
|
|
|
|
|
|
|
@ -93,6 +97,14 @@ class User(UserMixin, TimestampMixin, db.Model):
|
|
|
|
def load_user(id):
|
|
|
|
def load_user(id):
|
|
|
|
return User.query.get(int(id))
|
|
|
|
return User.query.get(int(id))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserPreferences(db.Model):
|
|
|
|
|
|
|
|
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
|
|
|
|
|
|
|
|
user = db.relationship('User', backref=db.backref('profile', uselist=False))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rating = db.Column(db.Enum(RATING), default=RATING.safe, nullable=False)
|
|
|
|
|
|
|
|
tag_blacklist = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
post_tags = db.Table('post_tags', db.metadata,
|
|
|
|
post_tags = db.Table('post_tags', db.metadata,
|
|
|
|
db.Column('post_id', db.Integer, db.ForeignKey('post.id')),
|
|
|
|
db.Column('post_id', db.Integer, db.ForeignKey('post.id')),
|
|
|
|
db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'))
|
|
|
|
db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'))
|
|
|
@ -184,6 +196,11 @@ class Post(TimestampMixin, db.Model):
|
|
|
|
def is_approved(self):
|
|
|
|
def is_approved(self):
|
|
|
|
return self.status is POST_STATUS.active
|
|
|
|
return self.status is POST_STATUS.active
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def can_edit(self):
|
|
|
|
|
|
|
|
author = current_user == self.author
|
|
|
|
|
|
|
|
moderator = current_user.is_moderator
|
|
|
|
|
|
|
|
return author or moderator
|
|
|
|
|
|
|
|
|
|
|
|
class Tag(TimestampMixin, db.Model):
|
|
|
|
class Tag(TimestampMixin, db.Model):
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
@ -208,4 +225,10 @@ class Comment(TimestampMixin, db.Model):
|
|
|
|
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
|
|
|
|
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
|
|
|
|
user = db.relationship('User', backref=db.backref('comments', lazy=True))
|
|
|
|
user = db.relationship('User', backref=db.backref('comments', lazy=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def can_edit(self):
|
|
|
|
|
|
|
|
author = current_user == self.user
|
|
|
|
|
|
|
|
moderator = current_user.is_moderator
|
|
|
|
|
|
|
|
return author or moderator
|
|
|
|
|
|
|
|
|
|
|
|
# THINK ABOUT LAZY LOADING
|
|
|
|
# THINK ABOUT LAZY LOADING
|
|
|
|