-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from paramsingh/comment-views
CB-295: Show comments on reviews and add ability to add comments.
- Loading branch information
Showing
7 changed files
with
178 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from flask_babel import lazy_gettext | ||
from flask_wtf import Form | ||
from wtforms import TextAreaField, StringField | ||
from wtforms.widgets import HiddenInput | ||
|
||
|
||
class CommentEditForm(Form): | ||
state = StringField(widget=HiddenInput(), default='publish') | ||
text = TextAreaField(lazy_gettext("Add a comment...")) | ||
review_id = StringField(widget=HiddenInput()) | ||
|
||
def __init__(self, review_id=None, **kwargs): | ||
kwargs['review_id'] = review_id | ||
Form.__init__(self, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# critiquebrainz - Repository for Creative Commons licensed reviews | ||
# | ||
# Copyright (C) 2018 MetaBrainz Foundation Inc. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
|
||
from flask import Blueprint, redirect, url_for | ||
from flask_login import current_user, login_required | ||
from critiquebrainz.frontend import flash | ||
from critiquebrainz.frontend.forms.comment import CommentEditForm | ||
|
||
import critiquebrainz.db.comment as db_comment | ||
|
||
comment_bp = Blueprint('comment', __name__) | ||
|
||
|
||
@comment_bp.route('/create', methods=['POST']) | ||
@login_required | ||
def create(): | ||
form = CommentEditForm() | ||
if form.validate_on_submit(): | ||
comment = db_comment.create( | ||
review_id=form.review_id.data, | ||
user_id=current_user.id, | ||
text=form.text.data, | ||
) | ||
flash.success('Comment has been saved!') | ||
return redirect(url_for('review.entity', id=comment['review_id'])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# critiquebrainz - Repository for Creative Commons licensed reviews | ||
# | ||
# Copyright (C) 2018 MetaBrainz Foundation Inc. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
|
||
import critiquebrainz.db.comment as db_comment | ||
import critiquebrainz.db.license as db_license | ||
import critiquebrainz.db.review as db_review | ||
import critiquebrainz.db.users as db_users | ||
|
||
from critiquebrainz.db.user import User | ||
from critiquebrainz.frontend.testing import FrontendTestCase | ||
|
||
|
||
class CommentViewsTestCase(FrontendTestCase): | ||
|
||
def setUp(self): | ||
super(CommentViewsTestCase, self).setUp() | ||
self.user = User(db_users.get_or_create("aef06569-098f-4218-a577-b413944d9493", new_user_data={ | ||
"display_name": u"Tester", | ||
})) | ||
self.license = db_license.create( | ||
id="CC BY-SA 3.0", | ||
full_name="Created so we can fill the form correctly.", | ||
) | ||
self.review = db_review.create( | ||
user_id=self.user.id, | ||
entity_id="e7aad618-fa86-3983-9e77-405e21796eca", | ||
entity_type="release_group", | ||
text="Testing", | ||
rating=5, | ||
is_draft=False, | ||
license_id=self.license["id"], | ||
) | ||
|
||
def test_create(self): | ||
self.temporary_login(self.user) | ||
payload = { | ||
'review_id': self.review['id'], | ||
'text': 'Hello, this is a comment!', | ||
'state': 'publish', | ||
} | ||
r = self.client.post( | ||
'/comments/create', | ||
data=payload, | ||
) | ||
|
||
self.assertRedirects(r, '/review/%s' % self.review['id']) | ||
count = db_comment.count_comments(review_id=self.review['id']) | ||
self.assertEqual(count, 1) |