diff options
Diffstat (limited to 'app/lib/django_comments/views')
-rw-r--r-- | app/lib/django_comments/views/comments.py | 17 | ||||
-rw-r--r-- | app/lib/django_comments/views/moderation.py | 14 |
2 files changed, 20 insertions, 11 deletions
diff --git a/app/lib/django_comments/views/comments.py b/app/lib/django_comments/views/comments.py index c441c30..40dfc60 100644 --- a/app/lib/django_comments/views/comments.py +++ b/app/lib/django_comments/views/comments.py @@ -3,13 +3,12 @@ from __future__ import absolute_import from django import http from django.apps import apps from django.conf import settings +from django.contrib.sites.shortcuts import get_current_site from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.shortcuts import render from django.template.loader import render_to_string from django.utils.html import escape -from django.views.decorators.csrf import csrf_protect -from django.views.decorators.csrf import csrf_exempt - +from django.views.decorators.csrf import csrf_protect, csrf_exempt from django.views.decorators.http import require_POST import django_comments @@ -41,7 +40,11 @@ def post_comment(request, next=None, using=None): """ # Fill out some initial data fields from an authenticated user, if present data = request.POST.copy() - if request.user.is_authenticated(): + try: + user_is_authenticated = request.user.is_authenticated() + except TypeError: # Django >= 1.11 + user_is_authenticated = request.user.is_authenticated + if user_is_authenticated: if not data.get('name', ''): data["name"] = request.user.get_full_name() or request.user.get_username() if not data.get('email', ''): @@ -102,9 +105,9 @@ def post_comment(request, next=None, using=None): ) # Otherwise create the comment - comment = form.get_comment_object() - comment.ip_address = request.META.get("REMOTE_ADDR", None) - if request.user.is_authenticated(): + comment = form.get_comment_object(site_id=get_current_site(request).id) + comment.ip_address = request.META.get("REMOTE_ADDR", None) or None + if user_is_authenticated: comment.user = request.user # Signal that the comment is about to be saved diff --git a/app/lib/django_comments/views/moderation.py b/app/lib/django_comments/views/moderation.py index 4460569..04c665f 100644 --- a/app/lib/django_comments/views/moderation.py +++ b/app/lib/django_comments/views/moderation.py @@ -1,7 +1,7 @@ from __future__ import absolute_import -from django.conf import settings from django.contrib.auth.decorators import login_required, permission_required +from django.contrib.sites.shortcuts import get_current_site from django.shortcuts import get_object_or_404, render from django.views.decorators.csrf import csrf_protect @@ -21,7 +21,9 @@ def flag(request, comment_id, next=None): comment the flagged `comments.comment` object """ - comment = get_object_or_404(django_comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID) + comment = get_object_or_404(django_comments.get_model(), + pk=comment_id, + site__pk=get_current_site(request).pk) # Flag on POST if request.method == 'POST': @@ -46,7 +48,9 @@ def delete(request, comment_id, next=None): comment the flagged `comments.comment` object """ - comment = get_object_or_404(django_comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID) + comment = get_object_or_404(django_comments.get_model(), + pk=comment_id, + site__pk=get_current_site(request).pk) # Delete on POST if request.method == 'POST': @@ -72,7 +76,9 @@ def approve(request, comment_id, next=None): comment the `comments.comment` object for approval """ - comment = get_object_or_404(django_comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID) + comment = get_object_or_404(django_comments.get_model(), + pk=comment_id, + site__pk=get_current_site(request).pk) # Delete on POST if request.method == 'POST': |