mirror of
https://git.wownero.com/wownero/wownero-funding-system.git
synced 2024-08-15 00:53:45 +00:00
Database logic for comments
This commit is contained in:
parent
5db9cb47ba
commit
863e91e3f2
3 changed files with 112 additions and 61 deletions
|
@ -83,7 +83,7 @@ class Proposal(base):
|
||||||
funds_target = sa.Column(sa.Float, nullable=False)
|
funds_target = sa.Column(sa.Float, nullable=False)
|
||||||
|
|
||||||
# the FFS progress (cached)
|
# 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)
|
# the FFS withdrawal amount (paid to the author)
|
||||||
funds_withdrew = sa.Column(sa.Float, nullable=False, default=0)
|
funds_withdrew = sa.Column(sa.Float, nullable=False, default=0)
|
||||||
|
@ -278,10 +278,50 @@ class Comment(base):
|
||||||
user = relationship("User", back_populates="comments")
|
user = relationship("User", back_populates="comments")
|
||||||
|
|
||||||
message = sa.Column(sa.VARCHAR, nullable=False)
|
message = sa.Column(sa.VARCHAR, nullable=False)
|
||||||
|
replied_to = sa.Column(sa.ForeignKey("comments.id"))
|
||||||
|
|
||||||
locked = sa.Column(sa.Boolean, default=False)
|
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
|
@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 flask.ext.login import current_user
|
||||||
from wowfunding.factory import db_session
|
from wowfunding.factory import db_session
|
||||||
if not message:
|
if not message:
|
||||||
|
@ -292,6 +332,11 @@ class Comment(base):
|
||||||
|
|
||||||
if not message_id:
|
if not message_id:
|
||||||
comment = Comment(user_id=self.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:
|
else:
|
||||||
try:
|
try:
|
||||||
user = db_session.query(User).filter(User.id == user_id).first()
|
user = db_session.query(User).filter(User.id == user_id).first()
|
||||||
|
|
|
@ -351,4 +351,12 @@ nav .nav-link .active{
|
||||||
#point-wow-left {
|
#point-wow-left {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textarea.comment{
|
||||||
|
padding-left: 6px;
|
||||||
|
padding-right: 6px;
|
||||||
|
padding-bottom: 6px;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 600px;
|
||||||
|
}
|
||||||
|
|
|
@ -3,64 +3,62 @@
|
||||||
<div class="card my-6" id="incoming_txs">
|
<div class="card my-6" id="incoming_txs">
|
||||||
<h5 class="card-header">Comments</h5>
|
<h5 class="card-header">Comments</h5>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
Comment functionality not made yet!<br>
|
{% if logged_in %}
|
||||||
Press <b>F</b> to pay respects.
|
<form method="post" action="comment">
|
||||||
|
<input type="hidden" name="proposal_id" value="{{proposal.id}}">
|
||||||
|
<textarea class="comment" name="text" rows="6" cols="60"></textarea>
|
||||||
|
<br><br><input type="submit" value="add comment">
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
|
You need to be logged in to comment.<br>
|
||||||
|
Press <b>F</b> to pay respects.
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<!-- Single Comment -->
|
||||||
|
<div class="media mb-4">
|
||||||
|
<img class="d-flex mr-3 rounded-circle" src="http://placehold.it/50x50" alt="">
|
||||||
|
<div class="media-body">
|
||||||
|
<h5 class="mt-0">Commenter Name</h5>
|
||||||
|
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.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Comment with nested comments -->
|
||||||
|
<div class="media mb-4">
|
||||||
|
<img class="d-flex mr-3 rounded-circle" src="http://placehold.it/50x50" alt="">
|
||||||
|
<div class="media-body">
|
||||||
|
<h5 class="mt-0">Commenter Name</h5>
|
||||||
|
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.
|
||||||
|
|
||||||
|
<div class="media mt-4">
|
||||||
|
<img class="d-flex mr-3 rounded-circle" src="http://placehold.it/50x50" alt="">
|
||||||
|
<div class="media-body">
|
||||||
|
<h5 class="mt-0">Commenter Name</h5>
|
||||||
|
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.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="media mt-4">
|
||||||
|
<img class="d-flex mr-3 rounded-circle" src="http://placehold.it/50x50" alt="">
|
||||||
|
<div class="media-body">
|
||||||
|
<h5 class="mt-0">Commenter Name</h5>
|
||||||
|
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.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--<!– Comments Form –>-->
|
|
||||||
<!--<div class="card my-4">-->
|
|
||||||
<!--<h5 class="card-header">Leave a Comment:</h5>-->
|
|
||||||
<!--<div class="card-body">-->
|
|
||||||
<!--<form>-->
|
|
||||||
<!--<div class="form-group">-->
|
|
||||||
<!--<textarea class="form-control" rows="3"></textarea>-->
|
|
||||||
<!--</div>-->
|
|
||||||
<!--<button type="submit" class="btn btn-primary">Submit</button>-->
|
|
||||||
<!--</form>-->
|
|
||||||
<!--</div>-->
|
|
||||||
<!--</div>-->
|
|
||||||
|
|
||||||
<!--<!– Single Comment –>-->
|
|
||||||
<!--<div class="media mb-4">-->
|
|
||||||
<!--<img class="d-flex mr-3 rounded-circle" src="http://placehold.it/50x50" alt="">-->
|
|
||||||
<!--<div class="media-body">-->
|
|
||||||
<!--<h5 class="mt-0">Commenter Name</h5>-->
|
|
||||||
<!--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.-->
|
|
||||||
<!--</div>-->
|
|
||||||
<!--</div>-->
|
|
||||||
|
|
||||||
<!--<!– Comment with nested comments –>-->
|
|
||||||
<!--<div class="media mb-4">-->
|
|
||||||
<!--<img class="d-flex mr-3 rounded-circle" src="http://placehold.it/50x50" alt="">-->
|
|
||||||
<!--<div class="media-body">-->
|
|
||||||
<!--<h5 class="mt-0">Commenter Name</h5>-->
|
|
||||||
<!--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.-->
|
|
||||||
|
|
||||||
<!--<div class="media mt-4">-->
|
|
||||||
<!--<img class="d-flex mr-3 rounded-circle" src="http://placehold.it/50x50" alt="">-->
|
|
||||||
<!--<div class="media-body">-->
|
|
||||||
<!--<h5 class="mt-0">Commenter Name</h5>-->
|
|
||||||
<!--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.-->
|
|
||||||
<!--</div>-->
|
|
||||||
<!--</div>-->
|
|
||||||
|
|
||||||
<!--<div class="media mt-4">-->
|
|
||||||
<!--<img class="d-flex mr-3 rounded-circle" src="http://placehold.it/50x50" alt="">-->
|
|
||||||
<!--<div class="media-body">-->
|
|
||||||
<!--<h5 class="mt-0">Commenter Name</h5>-->
|
|
||||||
<!--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.-->
|
|
||||||
<!--</div>-->
|
|
||||||
<!--</div>-->
|
|
||||||
|
|
||||||
<!--</div>-->
|
|
||||||
<!--</div>-->
|
|
Loading…
Add table
Add a link
Reference in a new issue