diff options
Diffstat (limited to 'app/lib/django_comments')
-rw-r--r-- | app/lib/django_comments/__init__.py | 13 | ||||
-rw-r--r-- | app/lib/django_comments/abstracts.py | 7 | ||||
-rw-r--r-- | app/lib/django_comments/forms.py | 10 | ||||
-rw-r--r-- | app/lib/django_comments/locale/eo/LC_MESSAGES/django.mo | bin | 4913 -> 5077 bytes | |||
-rw-r--r-- | app/lib/django_comments/locale/eo/LC_MESSAGES/django.po | 14 | ||||
-rw-r--r-- | app/lib/django_comments/locale/ko/LC_MESSAGES/django.mo | bin | 5400 -> 5403 bytes | |||
-rw-r--r-- | app/lib/django_comments/locale/ko/LC_MESSAGES/django.po | 9 | ||||
-rw-r--r-- | app/lib/django_comments/locale/nl/LC_MESSAGES/django.mo | bin | 5057 -> 5376 bytes | |||
-rw-r--r-- | app/lib/django_comments/locale/nl/LC_MESSAGES/django.po | 18 | ||||
-rw-r--r-- | app/lib/django_comments/locale/sq/LC_MESSAGES/django.mo | bin | 5263 -> 5374 bytes | |||
-rw-r--r-- | app/lib/django_comments/locale/sq/LC_MESSAGES/django.po | 11 | ||||
-rw-r--r-- | app/lib/django_comments/moderation.py | 5 | ||||
-rw-r--r-- | app/lib/django_comments/templatetags/comments.py | 9 | ||||
-rw-r--r-- | app/lib/django_comments/views/comments.py | 17 | ||||
-rw-r--r-- | app/lib/django_comments/views/moderation.py | 14 |
15 files changed, 82 insertions, 45 deletions
diff --git a/app/lib/django_comments/__init__.py b/app/lib/django_comments/__init__.py index c233b74..e4c5943 100644 --- a/app/lib/django_comments/__init__.py +++ b/app/lib/django_comments/__init__.py @@ -2,8 +2,11 @@ from importlib import import_module from django.apps import apps from django.conf import settings -from django.core import urlresolvers from django.core.exceptions import ImproperlyConfigured +try: + from django.urls import reverse +except ImportError: + from django.core.urlresolvers import reverse # Django < 1.10 DEFAULT_COMMENTS_APP = 'django_comments' @@ -68,7 +71,7 @@ def get_form_target(): if get_comment_app_name() != DEFAULT_COMMENTS_APP and hasattr(get_comment_app(), "get_form_target"): return get_comment_app().get_form_target() else: - return urlresolvers.reverse("comments-post-comment") + return reverse("comments-post-comment") def get_flag_url(comment): @@ -78,7 +81,7 @@ def get_flag_url(comment): if get_comment_app_name() != DEFAULT_COMMENTS_APP and hasattr(get_comment_app(), "get_flag_url"): return get_comment_app().get_flag_url(comment) else: - return urlresolvers.reverse("comments-flag", args=(comment.id,)) + return reverse("comments-flag", args=(comment.id,)) def get_delete_url(comment): @@ -88,7 +91,7 @@ def get_delete_url(comment): if get_comment_app_name() != DEFAULT_COMMENTS_APP and hasattr(get_comment_app(), "get_delete_url"): return get_comment_app().get_delete_url(comment) else: - return urlresolvers.reverse("comments-delete", args=(comment.id,)) + return reverse("comments-delete", args=(comment.id,)) def get_approve_url(comment): @@ -98,4 +101,4 @@ def get_approve_url(comment): if get_comment_app_name() != DEFAULT_COMMENTS_APP and hasattr(get_comment_app(), "get_approve_url"): return get_comment_app().get_approve_url(comment) else: - return urlresolvers.reverse("comments-approve", args=(comment.id,)) + return reverse("comments-approve", args=(comment.id,)) diff --git a/app/lib/django_comments/abstracts.py b/app/lib/django_comments/abstracts.py index 8004204..4fbb94a 100644 --- a/app/lib/django_comments/abstracts.py +++ b/app/lib/django_comments/abstracts.py @@ -4,11 +4,14 @@ from django.conf import settings from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType from django.contrib.sites.models import Site -from django.core import urlresolvers from django.db import models from django.utils import timezone from django.utils.encoding import python_2_unicode_compatible from django.utils.translation import ugettext_lazy as _ +try: + from django.urls import reverse +except ImportError: + from django.core.urlresolvers import reverse # Django < 1.10 from .managers import CommentManager @@ -39,7 +42,7 @@ class BaseCommentAbstractModel(models.Model): """ Get a URL suitable for redirecting to the content object. """ - return urlresolvers.reverse( + return reverse( "comments-url-redirect", args=(self.content_type_id, self.object_pk) ) diff --git a/app/lib/django_comments/forms.py b/app/lib/django_comments/forms.py index c1324e9..7b7eafd 100644 --- a/app/lib/django_comments/forms.py +++ b/app/lib/django_comments/forms.py @@ -56,8 +56,6 @@ class CommentSecurityForm(forms.Form): def clean_timestamp(self): """Make sure the timestamp isn't too far (default is > 2 hours) in the past.""" ts = self.cleaned_data["timestamp"] - if time.time() - ts > DEFAULT_COMMENTS_TIMEOUT: - raise forms.ValidationError("Timestamp check failed") return ts def generate_security_data(self): @@ -105,7 +103,7 @@ class CommentDetailsForm(CommentSecurityForm): comment = forms.CharField(label=_('Comment'), widget=forms.Textarea, max_length=COMMENT_MAX_LENGTH) - def get_comment_object(self): + def get_comment_object(self, site_id=None): """ Return a new (unsaved) comment object based on the information in this form. Assumes that the form is already validated and will throw a @@ -118,7 +116,7 @@ class CommentDetailsForm(CommentSecurityForm): raise ValueError("get_comment_object may only be called on valid forms") CommentModel = self.get_comment_model() - new = CommentModel(**self.get_comment_create_data()) + new = CommentModel(**self.get_comment_create_data(site_id=site_id)) new = self.check_for_duplicate_comment(new) return new @@ -131,7 +129,7 @@ class CommentDetailsForm(CommentSecurityForm): """ return get_model() - def get_comment_create_data(self): + def get_comment_create_data(self, site_id=None): """ Returns the dict of data to be used to create a comment. Subclasses in custom comment apps that override get_comment_model can override this @@ -145,7 +143,7 @@ class CommentDetailsForm(CommentSecurityForm): user_url=self.cleaned_data["url"], comment=self.cleaned_data["comment"], submit_date=timezone.now(), - site_id=settings.SITE_ID, + site_id=site_id or getattr(settings, "SITE_ID", None), is_public=True, is_removed=False, ) diff --git a/app/lib/django_comments/locale/eo/LC_MESSAGES/django.mo b/app/lib/django_comments/locale/eo/LC_MESSAGES/django.mo Binary files differindex 3fb4031..bb2a28f 100644 --- a/app/lib/django_comments/locale/eo/LC_MESSAGES/django.mo +++ b/app/lib/django_comments/locale/eo/LC_MESSAGES/django.mo diff --git a/app/lib/django_comments/locale/eo/LC_MESSAGES/django.po b/app/lib/django_comments/locale/eo/LC_MESSAGES/django.po index ee10cd7..c03e004 100644 --- a/app/lib/django_comments/locale/eo/LC_MESSAGES/django.po +++ b/app/lib/django_comments/locale/eo/LC_MESSAGES/django.po @@ -2,13 +2,14 @@ # # Translators: # Translators: +# Nikolay Korotkiy <sikmir@gmail.com>, 2016 msgid "" msgstr "" "Project-Id-Version: django-contrib-comments\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-06-22 17:28+0200\n" -"PO-Revision-Date: 2015-06-22 15:43+0000\n" -"Last-Translator: Claude Paroz <claude@2xlibre.net>\n" +"POT-Creation-Date: 2016-02-10 09:06+0100\n" +"PO-Revision-Date: 2016-11-11 12:09+0000\n" +"Last-Translator: Nikolay Korotkiy <sikmir@gmail.com>\n" "Language-Team: Esperanto (http://www.transifex.com/django/django-contrib-comments/language/eo/)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -74,7 +75,7 @@ msgstr "Lastaj komentoj ĉe %(site_name)s" #: forms.py:105 msgctxt "Person name" msgid "Name" -msgstr "" +msgstr "Nomo" #: forms.py:97 msgid "Email address" @@ -201,6 +202,11 @@ msgstr "komenta marko" msgid "comment flags" msgstr "komentaj markoj" +#: moderation.py:253 +#, python-format +msgid "[%(site)s] New comment posted on \"%(object)s\"" +msgstr "[%(site)s] Nova komento afiŝita \"%(object)s\"" + #: templates/comments/approve.html:4 msgid "Approve a comment" msgstr "Aprobi komenton" diff --git a/app/lib/django_comments/locale/ko/LC_MESSAGES/django.mo b/app/lib/django_comments/locale/ko/LC_MESSAGES/django.mo Binary files differindex 4e26b8b..727eedb 100644 --- a/app/lib/django_comments/locale/ko/LC_MESSAGES/django.mo +++ b/app/lib/django_comments/locale/ko/LC_MESSAGES/django.mo diff --git a/app/lib/django_comments/locale/ko/LC_MESSAGES/django.po b/app/lib/django_comments/locale/ko/LC_MESSAGES/django.po index 7984422..3b14d2b 100644 --- a/app/lib/django_comments/locale/ko/LC_MESSAGES/django.po +++ b/app/lib/django_comments/locale/ko/LC_MESSAGES/django.po @@ -3,15 +3,16 @@ # Translators: # Translators: # Jannis Leidel <jannis@leidel.info>, 2011 -# Jeong Seongtae <magno79@gmail.com>, 2016 +# Le Tartuffe <magno79@gmail.com>, 2016 +# Jiyoon, Ha <cryptography@konkuk.ac.kr>, 2016 # Yeonsu Bak <yeonsubak@gmail.com>, 2015 msgid "" msgstr "" "Project-Id-Version: django-contrib-comments\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2016-02-10 09:06+0100\n" -"PO-Revision-Date: 2016-07-12 17:53+0000\n" -"Last-Translator: Jeong Seongtae <magno79@gmail.com>\n" +"PO-Revision-Date: 2016-09-15 16:44+0000\n" +"Last-Translator: Jiyoon, Ha <cryptography@konkuk.ac.kr>\n" "Language-Team: Korean (http://www.transifex.com/django/django-contrib-comments/language/ko/)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -85,7 +86,7 @@ msgstr "URL" #: forms.py:99 msgid "Comment" -msgstr "코멘트:" +msgstr "코멘트" #: forms.py:177 #, python-format diff --git a/app/lib/django_comments/locale/nl/LC_MESSAGES/django.mo b/app/lib/django_comments/locale/nl/LC_MESSAGES/django.mo Binary files differindex dbeef7f..3b05375 100644 --- a/app/lib/django_comments/locale/nl/LC_MESSAGES/django.mo +++ b/app/lib/django_comments/locale/nl/LC_MESSAGES/django.mo diff --git a/app/lib/django_comments/locale/nl/LC_MESSAGES/django.po b/app/lib/django_comments/locale/nl/LC_MESSAGES/django.po index b55d19b..fddd817 100644 --- a/app/lib/django_comments/locale/nl/LC_MESSAGES/django.po +++ b/app/lib/django_comments/locale/nl/LC_MESSAGES/django.po @@ -3,15 +3,16 @@ # Translators: # Translators: # go2people <admin@go2people.nl>, 2011 +# Evelijn Saaltink <evelijnsaaltink@gmail.com>, 2016 # Jannis Leidel <jannis@leidel.info>, 2011 # Tino de Bruijn <tinodb@gmail.com>, 2011 msgid "" msgstr "" "Project-Id-Version: django-contrib-comments\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-06-22 17:28+0200\n" -"PO-Revision-Date: 2015-06-22 15:43+0000\n" -"Last-Translator: Claude Paroz <claude@2xlibre.net>\n" +"POT-Creation-Date: 2016-02-10 09:06+0100\n" +"PO-Revision-Date: 2016-10-12 18:03+0000\n" +"Last-Translator: Evelijn Saaltink <evelijnsaaltink@gmail.com>\n" "Language-Team: Dutch (http://www.transifex.com/django/django-contrib-comments/language/nl/)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -77,7 +78,7 @@ msgstr "Laatste opmerkingen op %(site_name)s" #: forms.py:105 msgctxt "Person name" msgid "Name" -msgstr "" +msgstr "Naam" #: forms.py:97 msgid "Email address" @@ -204,6 +205,11 @@ msgstr "opmerking vlag" msgid "comment flags" msgstr "opmerking vlaggen" +#: moderation.py:253 +#, python-format +msgid "[%(site)s] New comment posted on \"%(object)s\"" +msgstr "[%(site)s] Nieuwe opmerking geplaatst op \"%(object)s\"" + #: templates/comments/approve.html:4 msgid "Approve a comment" msgstr "Een opmerking toestaan" @@ -281,8 +287,8 @@ msgstr "Toon voorbeeld van uw opmerking" #: templates/comments/preview.html:11 msgid "Please correct the error below" msgid_plural "Please correct the errors below" -msgstr[0] "" -msgstr[1] "" +msgstr[0] "Please correct the error below" +msgstr[1] "Herstel de fouten hieronder" #: templates/comments/preview.html:16 msgid "Post your comment" diff --git a/app/lib/django_comments/locale/sq/LC_MESSAGES/django.mo b/app/lib/django_comments/locale/sq/LC_MESSAGES/django.mo Binary files differindex c4206c5..085c1d8 100644 --- a/app/lib/django_comments/locale/sq/LC_MESSAGES/django.mo +++ b/app/lib/django_comments/locale/sq/LC_MESSAGES/django.mo diff --git a/app/lib/django_comments/locale/sq/LC_MESSAGES/django.po b/app/lib/django_comments/locale/sq/LC_MESSAGES/django.po index d7f42d0..b50e3b5 100644 --- a/app/lib/django_comments/locale/sq/LC_MESSAGES/django.po +++ b/app/lib/django_comments/locale/sq/LC_MESSAGES/django.po @@ -3,13 +3,13 @@ # Translators: # Translators: # Besnik <besnik@programeshqip.org>, 2011 -# Besnik <besnik@programeshqip.org>, 2015 +# Besnik <besnik@programeshqip.org>, 2015-2016 msgid "" msgstr "" "Project-Id-Version: django-contrib-comments\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-06-22 17:28+0200\n" -"PO-Revision-Date: 2015-11-25 08:30+0000\n" +"POT-Creation-Date: 2016-02-10 09:06+0100\n" +"PO-Revision-Date: 2016-10-11 21:34+0000\n" "Last-Translator: Besnik <besnik@programeshqip.org>\n" "Language-Team: Albanian (http://www.transifex.com/django/django-contrib-comments/language/sq/)\n" "MIME-Version: 1.0\n" @@ -203,6 +203,11 @@ msgstr "shenjë komenti" msgid "comment flags" msgstr "shenja komenti" +#: moderation.py:253 +#, python-format +msgid "[%(site)s] New comment posted on \"%(object)s\"" +msgstr "[%(site)s] Koment i ri i postuar te \"%(object)s\"" + #: templates/comments/approve.html:4 msgid "Approve a comment" msgstr "Miratoni një koment" diff --git a/app/lib/django_comments/moderation.py b/app/lib/django_comments/moderation.py index f95e8ab..3e5c412 100644 --- a/app/lib/django_comments/moderation.py +++ b/app/lib/django_comments/moderation.py @@ -56,12 +56,11 @@ class. import datetime -from django import VERSION from django.conf import settings from django.contrib.sites.shortcuts import get_current_site from django.core.mail import send_mail from django.db.models.base import ModelBase -from django.template import Context, loader +from django.template import loader from django.utils import timezone from django.utils.translation import ugettext as _ @@ -254,7 +253,7 @@ class CommentModerator(object): 'site': get_current_site(request).name, 'object': content_object, } - message = t.render(Context(c) if VERSION < (1, 8) else c) + message = t.render(c) send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, recipient_list, fail_silently=True) diff --git a/app/lib/django_comments/templatetags/comments.py b/app/lib/django_comments/templatetags/comments.py index 75e5a0b..9b2d1a4 100644 --- a/app/lib/django_comments/templatetags/comments.py +++ b/app/lib/django_comments/templatetags/comments.py @@ -2,6 +2,7 @@ from django import template from django.template.loader import render_to_string from django.conf import settings from django.contrib.contenttypes.models import ContentType +from django.contrib.sites.shortcuts import get_current_site from django.utils.encoding import smart_text import django_comments @@ -76,10 +77,16 @@ class BaseCommentNode(template.Node): if not object_pk: return self.comment_model.objects.none() + # Explicit SITE_ID takes precedence over request. This is also how + # get_current_site operates. + site_id = getattr(settings, "SITE_ID", None) + if not site_id and ('request' in context): + site_id = get_current_site(context['request']).pk + qs = self.comment_model.objects.filter( content_type=ctype, object_pk=smart_text(object_pk), - site__pk=settings.SITE_ID, + site__pk=site_id, ) # The is_public and is_removed fields are implementation details of the 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': |