Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't send users to /comments/post/ with a form error if they try to comment without an email set (T206614) #220

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions TWLight/comments/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def get_form():
from .forms import CommentWithoutEmail
return CommentWithoutEmail
25 changes: 25 additions & 0 deletions TWLight/comments/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import datetime

from django_comments.forms import CommentForm
from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import force_unicode
from django.conf import settings


class CommentWithoutEmail(CommentForm):
def get_comment_create_data(self):
# Override the default comment form behaviour, with two left out fields
# From Stack Overflow https://stackoverflow.com/questions/1456267/django-comments-want-to-remove-user-url-not-expand-the-model-how-to/4766543#4766543
return dict(
content_type = ContentType.objects.get_for_model(self.target_object),
object_pk = force_unicode(self.target_object._get_pk_val()),
user_name = self.cleaned_data["name"],
comment = self.cleaned_data["comment"],
submit_date = datetime.datetime.now(),
site_id = settings.SITE_ID,
is_public = True,
is_removed = False,
)

CommentWithoutEmail.base_fields.pop('url')
CommentWithoutEmail.base_fields.pop('email')
3 changes: 2 additions & 1 deletion TWLight/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def get_languages_from_locale_subdirectories(dir):
'TWLight.applications',
'TWLight.emails',
'TWLight.graphs',
'TWLight.comments',
]

# dal (autocomplete_light) and modeltranslation must go before django.contrib.admin.
Expand Down Expand Up @@ -315,7 +316,7 @@ def get_languages_from_locale_subdirectories(dir):

# COMMENTS CONFIGURATION
# ------------------------------------------------------------------------------

COMMENTS_APP = 'TWLight.comments'

# TAGGIT CONFIGURATION
# ------------------------------------------------------------------------------
Expand Down