From f1ba83b6533b951bd80ee778af356970606092f6 Mon Sep 17 00:00:00 2001 From: Uri Zolotko Date: Tue, 5 Jan 2016 19:40:14 +0700 Subject: [PATCH 1/2] Support projects without fixed SITE_ID setting --- django_comments/templatetags/comments.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/django_comments/templatetags/comments.py b/django_comments/templatetags/comments.py index 62aeef0..77fbb71 100644 --- a/django_comments/templatetags/comments.py +++ b/django_comments/templatetags/comments.py @@ -78,9 +78,13 @@ def get_queryset(self, context): qs = self.comment_model.objects.filter( content_type=ctype, - object_pk=smart_text(object_pk), - site__pk=settings.SITE_ID, - ) + object_pk=smart_text(object_pk)) + try: + site_id = settings.SITE_ID + except AttributeError: + pass + else: + qs = qs.filter(site__pk=site_id) # The is_public and is_removed fields are implementation details of the # built-in comment model's spam filtering system, so they might not From c03d076806ecc2ad7efe120c49252d7167a7b2fa Mon Sep 17 00:00:00 2001 From: Uri Zolotko Date: Wed, 6 Jan 2016 11:17:51 +0700 Subject: [PATCH 2/2] fix post_comment() view when SITE_ID is not set --- django_comments/forms.py | 1 - django_comments/views/comments.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/django_comments/forms.py b/django_comments/forms.py index 814b5f9..cd94f27 100644 --- a/django_comments/forms.py +++ b/django_comments/forms.py @@ -143,7 +143,6 @@ def get_comment_create_data(self): user_url=self.cleaned_data["url"], comment=self.cleaned_data["comment"], submit_date=timezone.now(), - site_id=settings.SITE_ID, is_public=True, is_removed=False, ) diff --git a/django_comments/views/comments.py b/django_comments/views/comments.py index c03c3c3..1886bd7 100644 --- a/django_comments/views/comments.py +++ b/django_comments/views/comments.py @@ -3,8 +3,8 @@ from django import http from django.apps import apps from django.conf import settings +from django.contrib.sites.models import Site from django.core.exceptions import ObjectDoesNotExist, ValidationError -from django.db import models from django.shortcuts import render from django.template.loader import render_to_string from django.utils.html import escape @@ -105,6 +105,7 @@ def post_comment(request, next=None, using=None): comment.ip_address = request.META.get("REMOTE_ADDR", None) if request.user.is_authenticated(): comment.user = request.user + comment.site_id = Site.objects.get_current(request).pk # Signal that the comment is about to be saved responses = signals.comment_will_be_posted.send(