Skip to content

Commit

Permalink
No empty comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bimalkant-lauhny committed Oct 31, 2018
1 parent 136ccd6 commit 9249b8d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
8 changes: 8 additions & 0 deletions admin/schema_changes/13.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
BEGIN;

ALTER TABLE "comment_revision"
ALTER COLUMN text
SET NOT NULL,
ADD CHECK (text <> '');

COMMIT;
2 changes: 1 addition & 1 deletion admin/sql/create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CREATE TABLE comment_revision (
id SERIAL NOT NULL,
comment_id UUID NOT NULL,
"timestamp" TIMESTAMP NOT NULL DEFAULT NOW(),
text VARCHAR
text VARCHAR NOT NULL CHECK (text <> '')
);

CREATE TABLE license (
Expand Down
3 changes: 2 additions & 1 deletion critiquebrainz/frontend/forms/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
from flask_wtf import Form
from wtforms import TextAreaField, StringField
from wtforms.widgets import HiddenInput
from wtforms.validators import DataRequired


class CommentEditForm(Form):
state = StringField(widget=HiddenInput(), default='publish')
text = TextAreaField(lazy_gettext("Add a comment..."))
text = TextAreaField(lazy_gettext("Add a comment..."), validators=[DataRequired()])
review_id = StringField(widget=HiddenInput())

def __init__(self, review_id=None, **kwargs):
Expand Down
6 changes: 4 additions & 2 deletions critiquebrainz/frontend/views/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
def create():
form = CommentEditForm()
if form.validate_on_submit():
comment = db_comment.create(
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']))
else:
flash.error('Comment must not be empty!')
return redirect(url_for('review.entity', id=form.review_id.data))

0 comments on commit 9249b8d

Please sign in to comment.