Django

Code

Changeset 8589

Show
Ignore:
Timestamp:
08/26/08 13:53:52 (3 months ago)
Author:
jacob
Message:

Updated comment signals to provide enough information to actually act on. This was uncovered when working on the documentation, which'll be committed shortly.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/comments/signals.py

    r8557 r8589  
    1010# the same time (just before, actually) as the Comment object's pre-save signal, 
    1111# except that the HTTP request is sent along with this signal. 
    12 comment_will_be_posted = Signal(
     12comment_will_be_posted = Signal(providing_args=["comment", "request"]
    1313 
    1414# Sent just after a comment was posted. See above for how this differs 
    1515# from the Comment object's post-save signal. 
    16 comment_was_posted = Signal(
     16comment_was_posted = Signal(providing_args=["comment", "request"]
    1717 
    1818# Sent after a comment was "flagged" in some way. Check the flag to see if this 
    1919# was a user requesting removal of a comment, a moderator approving/removing a 
    2020# comment, or some other custom user flag. 
    21 comment_was_flagged = Signal(
     21comment_was_flagged = Signal(providing_args=["comment", "flag", "created", "request"]
  • django/trunk/django/contrib/comments/views/comments.py

    r8557 r8589  
    9797 
    9898    # Signal that the comment is about to be saved 
    99     responses = signals.comment_will_be_posted.send(comment) 
     99    responses = signals.comment_will_be_posted.send( 
     100        sender  = comment.__class__, 
     101        comment = comment, 
     102        request = request 
     103    ) 
    100104 
    101105    for (receiver, response) in responses: 
     
    106110    # Save the comment and signal that it was saved 
    107111    comment.save() 
    108     signals.comment_was_posted.send(comment) 
     112    signals.comment_was_posted.send( 
     113        sender  = comment.__class__, 
     114        comment = comment, 
     115        request = request 
     116    ) 
    109117 
    110118    return next_redirect(data, next, comment_done, c=comment._get_pk_val()) 
  • django/trunk/django/contrib/comments/views/moderation.py

    r8557 r8589  
    2828            flag    = comments.models.CommentFlag.SUGGEST_REMOVAL 
    2929        ) 
    30         signals.comment_was_flagged.send(comment) 
     30        signals.comment_was_flagged.send( 
     31            sender  = comment.__class__, 
     32            comment = comment, 
     33            flag    = flag, 
     34            created = created, 
     35            request = request, 
     36        ) 
    3137        return next_redirect(request.POST.copy(), next, flag_done, c=comment.pk) 
    3238 
     
    6268        comment.is_removed = True 
    6369        comment.save() 
    64         signals.comment_was_flagged.send(comment) 
     70        signals.comment_was_flagged.send( 
     71            sender  = comment.__class__, 
     72            comment = comment, 
     73            flag    = flag, 
     74            created = created, 
     75            request = request, 
     76        ) 
    6577        return next_redirect(request.POST.copy(), next, delete_done, c=comment.pk) 
    6678 
     
    99111        comment.save() 
    100112 
    101         signals.comment_was_flagged.send(comment) 
     113        signals.comment_was_flagged.send( 
     114            sender  = comment.__class__, 
     115            comment = comment, 
     116            flag    = flag, 
     117            created = created, 
     118            request = request, 
     119        ) 
    102120        return next_redirect(request.POST.copy(), next, approve_done, c=comment.pk) 
    103121 
  • django/trunk/tests/regressiontests/comment_tests/tests/comment_view_tests.py

    r8557 r8589  
    103103        # callback 
    104104        def receive(sender, **kwargs): 
    105             self.assertEqual(sender.comment, "This is my comment") 
    106             # TODO: Get the two commented tests below to work. 
    107 #            self.assertEqual(form_data["comment"], "This is my comment") 
    108 #            self.assertEqual(request.method, "POST") 
     105            self.assertEqual(kwargs['comment'].comment, "This is my comment") 
     106            self.assert_('request' in kwargs) 
    109107            received_signals.append(kwargs.get('signal')) 
    110108 
     
    118116        self.testCreateValidComment() 
    119117        self.assertEqual(received_signals, excepted_signals) 
    120  
     118         
    121119    def testWillBePostedSignal(self): 
    122120        """ 
     
    138136        """ 
    139137        def receive(sender, **kwargs): 
    140             sender.is_public = False # a bad but effective spam filter :)... 
     138             # a bad but effective spam filter :)... 
     139            kwargs['comment'].is_public = False 
    141140 
    142141        signals.comment_will_be_posted.connect(receive) 
  • django/trunk/tests/regressiontests/comment_tests/tests/moderation_view_tests.py

    r8557 r8589  
    4949        # callback 
    5050        def receive(sender, **kwargs): 
    51             flag = sender.flags.get(id=1) 
    52             self.assertEqual(flag.flag, CommentFlag.SUGGEST_REMOVAL) 
    53             self.assertEqual(flag.user.username, "normaluser") 
     51            self.assertEqual(kwargs['flag'].flag, CommentFlag.SUGGEST_REMOVAL) 
     52            self.assertEqual(kwargs['request'].user.username, "normaluser") 
    5453            received_signals.append(kwargs.get('signal')) 
    5554