mirror of https://github.com/django/django.git
The comments app was unconditionally accessing various settings that didn't
exist in Django's global settings. Changed those accesses to conditional lookups with default fallbacks. The comment_test tests now pass without needing to add any extra settings. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8573 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
47ed499a5d
commit
ccb37ce74c
|
@ -10,14 +10,14 @@ def get_comment_app():
|
||||||
Get the comment app (i.e. "django.contrib.comments") as defined in the settings
|
Get the comment app (i.e. "django.contrib.comments") as defined in the settings
|
||||||
"""
|
"""
|
||||||
# Make sure the app's in INSTALLED_APPS
|
# Make sure the app's in INSTALLED_APPS
|
||||||
comments_app = getattr(settings, 'COMMENTS_APP', 'django.contrib.comments')
|
comments_app = get_comment_app_name()
|
||||||
if comments_app not in settings.INSTALLED_APPS:
|
if comments_app not in settings.INSTALLED_APPS:
|
||||||
raise ImproperlyConfigured("The COMMENTS_APP (%r) "\
|
raise ImproperlyConfigured("The COMMENTS_APP (%r) "\
|
||||||
"must be in INSTALLED_APPS" % settings.COMMENTS_APP)
|
"must be in INSTALLED_APPS" % settings.COMMENTS_APP)
|
||||||
|
|
||||||
# Try to import the package
|
# Try to import the package
|
||||||
try:
|
try:
|
||||||
package = __import__(settings.COMMENTS_APP, '', '', [''])
|
package = __import__(comments_app, '', '', [''])
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImproperlyConfigured("The COMMENTS_APP setting refers to "\
|
raise ImproperlyConfigured("The COMMENTS_APP setting refers to "\
|
||||||
"a non-existing package.")
|
"a non-existing package.")
|
||||||
|
@ -31,6 +31,13 @@ def get_comment_app():
|
||||||
|
|
||||||
return package
|
return package
|
||||||
|
|
||||||
|
def get_comment_app_name():
|
||||||
|
"""
|
||||||
|
Returns the name of the comment app (either the setting value, if it
|
||||||
|
exists, or the default).
|
||||||
|
"""
|
||||||
|
return getattr(settings, 'COMMENTS_APP', 'django.contrib.comments')
|
||||||
|
|
||||||
def get_model():
|
def get_model():
|
||||||
from django.contrib.comments.models import Comment
|
from django.contrib.comments.models import Comment
|
||||||
return Comment
|
return Comment
|
||||||
|
@ -46,7 +53,7 @@ def get_flag_url(comment):
|
||||||
"""
|
"""
|
||||||
Get the URL for the "flag this comment" view.
|
Get the URL for the "flag this comment" view.
|
||||||
"""
|
"""
|
||||||
if settings.COMMENTS_APP != __name__ and hasattr(get_comment_app(), "get_flag_url"):
|
if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_flag_url"):
|
||||||
return get_comment_app().get_flag_url(comment)
|
return get_comment_app().get_flag_url(comment)
|
||||||
else:
|
else:
|
||||||
return urlresolvers.reverse("django.contrib.comments.views.moderation.flag", args=(comment.id,))
|
return urlresolvers.reverse("django.contrib.comments.views.moderation.flag", args=(comment.id,))
|
||||||
|
@ -55,7 +62,7 @@ def get_delete_url(comment):
|
||||||
"""
|
"""
|
||||||
Get the URL for the "delete this comment" view.
|
Get the URL for the "delete this comment" view.
|
||||||
"""
|
"""
|
||||||
if settings.COMMENTS_APP != __name__ and hasattr(get_comment_app(), "get_delete_url"):
|
if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_delete_url"):
|
||||||
return get_comment_app().get_flag_url(get_delete_url)
|
return get_comment_app().get_flag_url(get_delete_url)
|
||||||
else:
|
else:
|
||||||
return urlresolvers.reverse("django.contrib.comments.views.moderation.delete", args=(comment.id,))
|
return urlresolvers.reverse("django.contrib.comments.views.moderation.delete", args=(comment.id,))
|
||||||
|
@ -64,7 +71,7 @@ def get_approve_url(comment):
|
||||||
"""
|
"""
|
||||||
Get the URL for the "approve this comment from moderation" view.
|
Get the URL for the "approve this comment from moderation" view.
|
||||||
"""
|
"""
|
||||||
if settings.COMMENTS_APP != __name__ and hasattr(get_comment_app(), "get_approve_url"):
|
if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_approve_url"):
|
||||||
return get_comment_app().get_approve_url(comment)
|
return get_comment_app().get_approve_url(comment)
|
||||||
else:
|
else:
|
||||||
return urlresolvers.reverse("django.contrib.comments.views.moderation.approve", args=(comment.id,))
|
return urlresolvers.reverse("django.contrib.comments.views.moderation.approve", args=(comment.id,))
|
||||||
|
|
|
@ -81,7 +81,7 @@ class BaseCommentNode(template.Node):
|
||||||
site__pk = settings.SITE_ID,
|
site__pk = settings.SITE_ID,
|
||||||
is_public = True,
|
is_public = True,
|
||||||
)
|
)
|
||||||
if settings.COMMENTS_HIDE_REMOVED:
|
if getattr(settings, 'COMMENTS_HIDE_REMOVED', True):
|
||||||
qs = qs.filter(is_removed=False)
|
qs = qs.filter(is_removed=False)
|
||||||
|
|
||||||
return qs
|
return qs
|
||||||
|
|
Loading…
Reference in New Issue