|
@ -105,6 +105,7 @@ class User(UserMixin, db.Model): |
|
|
backref=db.backref('followed', lazy='joined'), |
|
|
backref=db.backref('followed', lazy='joined'), |
|
|
lazy='dynamic', |
|
|
lazy='dynamic', |
|
|
cascade='all, delete-orphan') |
|
|
cascade='all, delete-orphan') |
|
|
|
|
|
comments = db.relationship('Comment', backref='author', lazy='dynamic') |
|
|
|
|
|
|
|
|
def __init__(self, **kwargs): |
|
|
def __init__(self, **kwargs): |
|
|
super(User, self).__init__(**kwargs) |
|
|
super(User, self).__init__(**kwargs) |
|
@ -251,6 +252,7 @@ class Post(db.Model): |
|
|
body_html = db.Column(db.Text) |
|
|
body_html = db.Column(db.Text) |
|
|
timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) |
|
|
timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) |
|
|
author_id = db.Column(db.Integer, db.ForeignKey('users.id')) |
|
|
author_id = db.Column(db.Integer, db.ForeignKey('users.id')) |
|
|
|
|
|
comments = db.relationship('Comment', backref='post', lazy='dynamic') |
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def on_changed_body(target, value, oldvalue, initiator): |
|
|
def on_changed_body(target, value, oldvalue, initiator): |
|
@ -265,6 +267,28 @@ class Post(db.Model): |
|
|
db.event.listen(Post.body, 'set', Post.on_changed_body) |
|
|
db.event.listen(Post.body, 'set', Post.on_changed_body) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Comment(db.Model): |
|
|
|
|
|
__tablename__ = 'comments' |
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True) |
|
|
|
|
|
body = db.Column(db.Text) |
|
|
|
|
|
body_html = db.Column(db.Text) |
|
|
|
|
|
timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) |
|
|
|
|
|
disabled = db.Column(db.Boolean) |
|
|
|
|
|
author_id = db.Column(db.Integer, db.ForeignKey('users.id')) |
|
|
|
|
|
post_id = db.Column(db.Integer, db.ForeignKey('posts.id')) |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
|
def on_changed_body(target, value, oldvalue, initiator): |
|
|
|
|
|
allowed_tags = ['a', 'abbr', 'acronym', 'b', 'code', 'em', 'i', |
|
|
|
|
|
'strong'] |
|
|
|
|
|
md = markdown(value, output_format='html') |
|
|
|
|
|
clean_md = bleach.clean(md, tags=allowed_tags, strip=True) |
|
|
|
|
|
target.body_html = bleach.linkify(clean_md) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.event.listen(Comment.body, 'set', Comment.on_changed_body) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AnonymousUser(AnonymousUserMixin): |
|
|
class AnonymousUser(AnonymousUserMixin): |
|
|
def can(self, perm): |
|
|
def can(self, perm): |
|
|
return False |
|
|
return False |
|
|