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

Support projects without fixed SITE_ID setting #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion django_comments/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
10 changes: 7 additions & 3 deletions django_comments/templatetags/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion django_comments/views/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down