From fe6abf33c1054cc2200a766f25c8b75691d9ef18 Mon Sep 17 00:00:00 2001 From: Sn0wCrack Date: Mon, 15 May 2017 17:38:03 +1000 Subject: [PATCH] Added ability for users to leave anonymous comments --- nyaa/forms.py | 2 ++ nyaa/routes.py | 6 +++++- nyaa/templates/view.html | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/nyaa/forms.py b/nyaa/forms.py index a440092..1fec2ee 100644 --- a/nyaa/forms.py +++ b/nyaa/forms.py @@ -132,6 +132,8 @@ class CommentForm(FlaskForm): Required() ]) + is_anonymous = BooleanField('Anonymous') + class EditForm(FlaskForm): display_name = StringField('Torrent display name', [ diff --git a/nyaa/routes.py b/nyaa/routes.py index cd97e56..82aa062 100644 --- a/nyaa/routes.py +++ b/nyaa/routes.py @@ -611,7 +611,11 @@ def submit_comment(torrent_id): comment_text = (form.comment.data or '').strip() # Null entry for User just means Anonymous - current_user_id = flask.g.user.id if flask.g.user else None + if flask.g.user is None or form.is_anonymous.data: + current_user_id = None + else: + current_user_id = flask.g.user.id + comment = models.Comment( torrent=torrent_id, user_id=current_user_id, diff --git a/nyaa/templates/view.html b/nyaa/templates/view.html index 0dc90a9..4ed7c8d 100644 --- a/nyaa/templates/view.html +++ b/nyaa/templates/view.html @@ -173,6 +173,7 @@
{{ form.csrf_token }} {{ render_field(form.comment, class_='form-control') }} + {{ render_field(form.is_anonymous) }}