diff options
author | luxagraf <sng@luxagraf.net> | 2017-09-26 17:49:20 -0600 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2017-09-26 17:49:20 -0600 |
commit | e9eb2c612156894e87b9fa6584c1f8d05f932fe7 (patch) | |
tree | dc9ee22c618eade87186086d1b09b82bd54ffcbe /app/lib/django_comments/__init__.py | |
parent | a5f1c0580091f21fa4fd8817b41c55fa2ff6d0dc (diff) |
updated comments app to work with 1.11
Diffstat (limited to 'app/lib/django_comments/__init__.py')
-rw-r--r-- | app/lib/django_comments/__init__.py | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/app/lib/django_comments/__init__.py b/app/lib/django_comments/__init__.py index 225b195..c233b74 100644 --- a/app/lib/django_comments/__init__.py +++ b/app/lib/django_comments/__init__.py @@ -1,29 +1,36 @@ +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 -from importlib import import_module + DEFAULT_COMMENTS_APP = 'django_comments' + def get_comment_app(): """ Get the comment app (i.e. "django_comments") as defined in the settings """ # Make sure the app's in INSTALLED_APPS comments_app = get_comment_app_name() - if comments_app not in settings.INSTALLED_APPS: - raise ImproperlyConfigured("The COMMENTS_APP (%r) "\ - "must be in INSTALLED_APPS" % settings.COMMENTS_APP) + if not apps.is_installed(comments_app): + raise ImproperlyConfigured( + "The COMMENTS_APP (%r) must be in INSTALLED_APPS" % comments_app + ) # Try to import the package try: package = import_module(comments_app) except ImportError as e: - raise ImproperlyConfigured("The COMMENTS_APP setting refers to "\ - "a non-existing package. (%s)" % e) + raise ImproperlyConfigured( + "The COMMENTS_APP setting refers to a non-existing package. (%s)" % e + ) return package + def get_comment_app_name(): """ Returns the name of the comment app (either the setting value, if it @@ -31,16 +38,18 @@ def get_comment_app_name(): """ return getattr(settings, 'COMMENTS_APP', DEFAULT_COMMENTS_APP) + def get_model(): - from django_comments.models import Comment """ Returns the comment model class. """ if get_comment_app_name() != DEFAULT_COMMENTS_APP and hasattr(get_comment_app(), "get_model"): return get_comment_app().get_model() else: + from django_comments.models import Comment return Comment + def get_form(): from django_comments.forms import CommentForm """ @@ -51,6 +60,7 @@ def get_form(): else: return CommentForm + def get_form_target(): """ Returns the target URL for the comment form submission view. @@ -58,7 +68,8 @@ 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("django_comments.views.comments.post_comment") + return urlresolvers.reverse("comments-post-comment") + def get_flag_url(comment): """ @@ -67,8 +78,8 @@ 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("django_comments.views.moderation.flag", - args=(comment.id,)) + return urlresolvers.reverse("comments-flag", args=(comment.id,)) + def get_delete_url(comment): """ @@ -77,8 +88,8 @@ 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("django_comments.views.moderation.delete", - args=(comment.id,)) + return urlresolvers.reverse("comments-delete", args=(comment.id,)) + def get_approve_url(comment): """ @@ -87,5 +98,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("django_comments.views.moderation.approve", - args=(comment.id,)) + return urlresolvers.reverse("comments-approve", args=(comment.id,)) |