Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit ccb37ce74cae13115a65b4cb73db156d40131765 1 parent 47ed499
Malcolm Tredinnick authored August 26, 2008
17  django/contrib/comments/__init__.py
@@ -10,14 +10,14 @@ def get_comment_app():
10 10
     Get the comment app (i.e. "django.contrib.comments") as defined in the settings
11 11
     """
12 12
     # Make sure the app's in INSTALLED_APPS
13  
-    comments_app = getattr(settings, 'COMMENTS_APP', 'django.contrib.comments')
  13
+    comments_app = get_comment_app_name()
14 14
     if comments_app not in settings.INSTALLED_APPS:
15 15
         raise ImproperlyConfigured("The COMMENTS_APP (%r) "\
16 16
                                    "must be in INSTALLED_APPS" % settings.COMMENTS_APP)
17 17
 
18 18
     # Try to import the package
19 19
     try:
20  
-        package = __import__(settings.COMMENTS_APP, '', '', [''])
  20
+        package = __import__(comments_app, '', '', [''])
21 21
     except ImportError:
22 22
         raise ImproperlyConfigured("The COMMENTS_APP setting refers to "\
23 23
                                    "a non-existing package.")
@@ -31,6 +31,13 @@ def get_comment_app():
31 31
 
32 32
     return package
33 33
 
  34
+def get_comment_app_name():
  35
+    """
  36
+    Returns the name of the comment app (either the setting value, if it
  37
+    exists, or the default).
  38
+    """
  39
+    return getattr(settings, 'COMMENTS_APP', 'django.contrib.comments')
  40
+
34 41
 def get_model():
35 42
     from django.contrib.comments.models import Comment
36 43
     return Comment
@@ -46,7 +53,7 @@ def get_flag_url(comment):
46 53
     """
47 54
     Get the URL for the "flag this comment" view.
48 55
     """
49  
-    if settings.COMMENTS_APP != __name__ and hasattr(get_comment_app(), "get_flag_url"):
  56
+    if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_flag_url"):
50 57
         return get_comment_app().get_flag_url(comment)
51 58
     else:
52 59
         return urlresolvers.reverse("django.contrib.comments.views.moderation.flag", args=(comment.id,))
@@ -55,7 +62,7 @@ def get_delete_url(comment):
55 62
     """
56 63
     Get the URL for the "delete this comment" view.
57 64
     """
58  
-    if settings.COMMENTS_APP != __name__ and hasattr(get_comment_app(), "get_delete_url"):
  65
+    if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_delete_url"):
59 66
         return get_comment_app().get_flag_url(get_delete_url)
60 67
     else:
61 68
         return urlresolvers.reverse("django.contrib.comments.views.moderation.delete", args=(comment.id,))
@@ -64,7 +71,7 @@ def get_approve_url(comment):
64 71
     """
65 72
     Get the URL for the "approve this comment from moderation" view.
66 73
     """
67  
-    if settings.COMMENTS_APP != __name__ and hasattr(get_comment_app(), "get_approve_url"):
  74
+    if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_approve_url"):
68 75
         return get_comment_app().get_approve_url(comment)
69 76
     else:
70 77
         return urlresolvers.reverse("django.contrib.comments.views.moderation.approve", args=(comment.id,))
2  django/contrib/comments/templatetags/comments.py
@@ -81,7 +81,7 @@ def get_query_set(self, context):
81 81
             site__pk     = settings.SITE_ID,
82 82
             is_public    = True,
83 83
         )
84  
-        if settings.COMMENTS_HIDE_REMOVED:
  84
+        if getattr(settings, 'COMMENTS_HIDE_REMOVED', True):
85 85
             qs = qs.filter(is_removed=False)
86 86
 
87 87
         return qs

0 notes on commit ccb37ce

Please sign in to comment.
Something went wrong with that request. Please try again.