diff --git a/wowfunding/orm/orm.py b/wowfunding/orm/orm.py index 8173b8f..4663a6d 100644 --- a/wowfunding/orm/orm.py +++ b/wowfunding/orm/orm.py @@ -83,7 +83,7 @@ class Proposal(base): funds_target = sa.Column(sa.Float, nullable=False) # the FFS progress (cached) - funds_progress = sa.Column(sa.Float, nullable=False) + funds_progress = sa.Column(sa.Float, nullable=False, default=0) # the FFS withdrawal amount (paid to the author) funds_withdrew = sa.Column(sa.Float, nullable=False, default=0) @@ -278,10 +278,50 @@ class Comment(base): user = relationship("User", back_populates="comments") message = sa.Column(sa.VARCHAR, nullable=False) + replied_to = sa.Column(sa.ForeignKey("comments.id")) + locked = sa.Column(sa.Boolean, default=False) + @staticmethod + def get(comment_id: int): + from wowfunding.factory import db_session + return db_session.query(Comment).filter(Comment.id == comment_id).first() + + @staticmethod + def remove(comment_id: int): + from wowfunding.factory import db_session + from flask.ext.login import current_user + if current_user.id != user_id and not current_user.admin: + raise Exception("no rights to remove this comment") + comment = Comment.get(comment_id=comment_id) + try: + comment.delete() + db_session.commit() + db_session.flush() + except: + db_session.rollback() + raise + + @staticmethod + def lock(comment_id: int): + from wowfunding.factory import db_session + from flask.ext.login import current_user + if not current_user.admin: + raise Exception("admin required") + comment = Comment.get(comment_id=comment_id) + if not comment: + raise Exception("comment by that id not found") + comment.locked = True + try: + db_session.commit() + db_session.flush() + return comment + except: + db_session.rollback() + raise + @classmethod - def add_comment(cls, user_id: int, message: str, message_id: int = None): + def add_comment(cls, user_id: int, message: str, replied_to: int, message_id: int = None): from flask.ext.login import current_user from wowfunding.factory import db_session if not message: @@ -292,6 +332,11 @@ class Comment(base): if not message_id: comment = Comment(user_id=self.id) + if replied_to: + parent = Comment.get(comment_id=comment_id) + if not parent: + raise Exception("cannot reply to a non-existent comment") + comment.replied_to = parent.id else: try: user = db_session.query(User).filter(User.id == user_id).first() diff --git a/wowfunding/static/css/wow.css b/wowfunding/static/css/wow.css index a005abc..308c643 100644 --- a/wowfunding/static/css/wow.css +++ b/wowfunding/static/css/wow.css @@ -351,4 +351,12 @@ nav .nav-link .active{ #point-wow-left { display: none; } -} \ No newline at end of file +} + +textarea.comment{ + padding-left: 6px; + padding-right: 6px; + padding-bottom: 6px; + width: 100%; + max-width: 600px; +} diff --git a/wowfunding/templates/comments.html b/wowfunding/templates/comments.html index a9d0da7..89d655d 100644 --- a/wowfunding/templates/comments.html +++ b/wowfunding/templates/comments.html @@ -3,64 +3,62 @@
Comments
- Comment functionality not made yet!
- Press F to pay respects. -
-
- - - - - - - - - - - - - - + {% if logged_in %} +
+ + +

+
+ {% else %} + You need to be logged in to comment.
+ Press F to pay respects. + {% endif %} + +
- - - - - - - - - - + +
+ +
+
Commenter Name
+ Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras + purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi + vulputate fringilla. Donec lacinia congue felis in faucibus. +
+
- - - - - - - - + +
+ +
+
Commenter Name
+ Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras + purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi + vulputate fringilla. Donec lacinia congue felis in faucibus. - - - - - - - - - +
+ +
+
Commenter Name
+ Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. + Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc + ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus. +
+
- - - - - - - - - +
+ +
+
Commenter Name
+ Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. + Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc + ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus. +
+
- - +
+
+ + + + \ No newline at end of file