Ticket #8630: 8630_r9776.diff

File 8630_r9776.diff, 7.3 KB (added by Carl Meyer, 16 years ago)

updated patch with minor typo fixes

  • django/contrib/comments/admin.py

     
    11from django.contrib import admin
    22from django.contrib.comments.models import Comment
    33from django.utils.translation import ugettext_lazy as _
     4from django.contrib.comments import get_model
    45
    56class CommentsAdmin(admin.ModelAdmin):
    67    fieldsets = (
     
    2122    ordering = ('-submit_date',)
    2223    search_fields = ('comment', 'user__username', 'user_name', 'user_email', 'user_url', 'ip_address')
    2324
    24 admin.site.register(Comment, CommentsAdmin)
     25if get_model() is Comment:
     26    admin.site.register(Comment, CommentsAdmin)
  • django/contrib/comments/__init__.py

     
    22from django.core import urlresolvers
    33from django.core.exceptions import ImproperlyConfigured
    44
    5 # Attributes required in the top-level app for COMMENTS_APP
    6 REQUIRED_COMMENTS_APP_ATTRIBUTES = ["get_model", "get_form", "get_form_target"]
    7 
    85def get_comment_app():
    96    """
    107    Get the comment app (i.e. "django.contrib.comments") as defined in the settings
     
    2219        raise ImproperlyConfigured("The COMMENTS_APP setting refers to "\
    2320                                   "a non-existing package.")
    2421
    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 
    3222    return package
    3323
    3424def get_comment_app_name():
     
    3929    return getattr(settings, 'COMMENTS_APP', 'django.contrib.comments')
    4030
    4131def get_model():
     32    if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_model"):
     33        return get_comment_app().get_model()
    4234    from django.contrib.comments.models import Comment
    4335    return Comment
    4436
    4537def get_form():
     38    if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_form"):
     39        return get_comment_app().get_form()
    4640    from django.contrib.comments.forms import CommentForm
    4741    return CommentForm
    4842
    4943def 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()
    5046    return urlresolvers.reverse("django.contrib.comments.views.comments.post_comment")
    5147
    5248def get_flag_url(comment):
     
    5551    """
    5652    if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_flag_url"):
    5753        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,))
    6055
    6156def get_delete_url(comment):
    6257    """
    6358    Get the URL for the "delete this comment" view.
    6459    """
    6560    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,))
    6963
    7064def get_approve_url(comment):
    7165    """
     
    7367    """
    7468    if get_comment_app_name() != __name__ and hasattr(get_comment_app(), "get_approve_url"):
    7569        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

     
    2828        c = Comment(id=12345)
    2929        self.assertEqual(comments.get_approve_url(c), "/approve/12345/")
    3030
     31
     32class 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

     
    164164considerations you'll need to make if you're using this aproach.
    165165
    166166.. templatetag:: comment_form_target
     167.. _notes-on-the-comment-form:
    167168
    168169Getting the comment form target
    169170~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
    212213   settings
    213214   signals
    214215   upgrade
    215 
     216   custom
  • docs/ref/contrib/comments/settings.txt

     
    2929COMMENTS_APP
    3030------------
    3131
    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.
     32An app which provides :ref:`customization of the comments framework
     33<ref-contrib-comments-custom>`.  Use the same dotted-string notation
     34as in :setting:`INSTALLED_APPS`.  Your custom :setting:`COMMENTS_APP`
     35must also be listed in :setting:`INSTALLED_APPS`.
Back to Top