Ticket #8630: 8630_r9776.diff
File 8630_r9776.diff, 7.3 KB (added by , 16 years ago) |
---|
-
django/contrib/comments/admin.py
1 1 from django.contrib import admin 2 2 from django.contrib.comments.models import Comment 3 3 from django.utils.translation import ugettext_lazy as _ 4 from django.contrib.comments import get_model 4 5 5 6 class CommentsAdmin(admin.ModelAdmin): 6 7 fieldsets = ( … … 21 22 ordering = ('-submit_date',) 22 23 search_fields = ('comment', 'user__username', 'user_name', 'user_email', 'user_url', 'ip_address') 23 24 24 admin.site.register(Comment, CommentsAdmin) 25 if get_model() is Comment: 26 admin.site.register(Comment, CommentsAdmin) -
django/contrib/comments/__init__.py
2 2 from django.core import urlresolvers 3 3 from django.core.exceptions import ImproperlyConfigured 4 4 5 # Attributes required in the top-level app for COMMENTS_APP6 REQUIRED_COMMENTS_APP_ATTRIBUTES = ["get_model", "get_form", "get_form_target"]7 8 5 def get_comment_app(): 9 6 """ 10 7 Get the comment app (i.e. "django.contrib.comments") as defined in the settings … … 22 19 raise ImproperlyConfigured("The COMMENTS_APP setting refers to "\ 23 20 "a non-existing package.") 24 21 25 # Make sure some specific attributes exist inside that package.26 for attribute in REQUIRED_COMMENTS_APP_ATTRIBUTES:27 if not hasattr(package, attribute):28 raise ImproperlyConfigured("The COMMENTS_APP package %r does not "\29 "define the (required) %r function" % \30 (package, attribute))31 32 22 return package 33 23 34 24 def get_comment_app_name(): … … 39 29 return getattr(settings, 'COMMENTS_APP', 'django.contrib.comments') 40 30 41 31 def get_model(): 32 if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_model"): 33 return get_comment_app().get_model() 42 34 from django.contrib.comments.models import Comment 43 35 return Comment 44 36 45 37 def get_form(): 38 if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_form"): 39 return get_comment_app().get_form() 46 40 from django.contrib.comments.forms import CommentForm 47 41 return CommentForm 48 42 49 43 def get_form_target(): 44 if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_form_target"): 45 return get_comment_app().get_form_target() 50 46 return urlresolvers.reverse("django.contrib.comments.views.comments.post_comment") 51 47 52 48 def get_flag_url(comment): … … 55 51 """ 56 52 if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_flag_url"): 57 53 return get_comment_app().get_flag_url(comment) 58 else: 59 return urlresolvers.reverse("django.contrib.comments.views.moderation.flag", args=(comment.id,)) 54 return urlresolvers.reverse("django.contrib.comments.views.moderation.flag", args=(comment.id,)) 60 55 61 56 def get_delete_url(comment): 62 57 """ 63 58 Get the URL for the "delete this comment" view. 64 59 """ 65 60 if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_delete_url"): 66 return get_comment_app().get_flag_url(get_delete_url) 67 else: 68 return urlresolvers.reverse("django.contrib.comments.views.moderation.delete", args=(comment.id,)) 61 return get_comment_app().get_delete_url(comment) 62 return urlresolvers.reverse("django.contrib.comments.views.moderation.delete", args=(comment.id,)) 69 63 70 64 def get_approve_url(comment): 71 65 """ … … 73 67 """ 74 68 if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_approve_url"): 75 69 return get_comment_app().get_approve_url(comment) 76 else: 77 return urlresolvers.reverse("django.contrib.comments.views.moderation.approve", args=(comment.id,)) 70 return urlresolvers.reverse("django.contrib.comments.views.moderation.approve", args=(comment.id,)) -
tests/regressiontests/comment_tests/tests/app_api_tests.py
28 28 c = Comment(id=12345) 29 29 self.assertEqual(comments.get_approve_url(c), "/approve/12345/") 30 30 31 32 class CustomCommentTest(CommentTestCase): 33 urls = 'regressiontests.comment_tests.urls' 34 35 def setUp(self): 36 self.old_comments_app = getattr(settings, 'COMMENTS_APP', None) 37 settings.COMMENTS_APP = 'regressiontests.comment_tests.custom_comments' 38 settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + [settings.COMMENTS_APP,] 39 40 def tearDown(self): 41 del settings.INSTALLED_APPS[-1] 42 settings.COMMENTS_APP = self.old_comments_app 43 if settings.COMMENTS_APP is None: 44 delattr(settings._target, 'COMMENTS_APP') 45 46 def testGetCommentApp(self): 47 from regressiontests.comment_tests import custom_comments 48 self.assertEqual(comments.get_comment_app(), custom_comments) 49 50 def testGetModel(self): 51 from regressiontests.comment_tests.custom_comments.models import CustomComment 52 self.assertEqual(comments.get_model(), CustomComment) 53 54 def testGetForm(self): 55 from regressiontests.comment_tests.custom_comments.forms import CustomCommentForm 56 self.assertEqual(comments.get_form(), CustomCommentForm) 57 58 def testGetFormTarget(self): 59 self.assertEqual(comments.get_form_target(), "/post/") 60 61 def testGetFlagURL(self): 62 c = Comment(id=12345) 63 self.assertEqual(comments.get_flag_url(c), "/flag/12345/") 64 65 def getGetDeleteURL(self): 66 c = Comment(id=12345) 67 self.assertEqual(comments.get_delete_url(c), "/delete/12345/") 68 69 def getGetApproveURL(self): 70 c = Comment(id=12345) 71 self.assertEqual(comments.get_approve_url(c), "/approve/12345/") -
docs/ref/contrib/comments/index.txt
164 164 considerations you'll need to make if you're using this aproach. 165 165 166 166 .. templatetag:: comment_form_target 167 .. _notes-on-the-comment-form: 167 168 168 169 Getting the comment form target 169 170 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 212 213 settings 213 214 signals 214 215 upgrade 215 216 custom -
docs/ref/contrib/comments/settings.txt
29 29 COMMENTS_APP 30 30 ------------ 31 31 32 The app (i.e. entry in ``INSTALLED_APPS``) responsible for all "business logic." 33 You can change this to provide custom comment models and forms, though this is 34 currently undocumented. 32 An app which provides :ref:`customization of the comments framework 33 <ref-contrib-comments-custom>`. Use the same dotted-string notation 34 as in :setting:`INSTALLED_APPS`. Your custom :setting:`COMMENTS_APP` 35 must also be listed in :setting:`INSTALLED_APPS`.