Author: jacob
Date: 2008-08-26 13:53:52 -0500 (Tue, 26 Aug 2008)
New Revision: 8589

Modified:
   django/trunk/django/contrib/comments/signals.py
   django/trunk/django/contrib/comments/views/comments.py
   django/trunk/django/contrib/comments/views/moderation.py
   django/trunk/tests/regressiontests/comment_tests/tests/comment_view_tests.py
   
django/trunk/tests/regressiontests/comment_tests/tests/moderation_view_tests.py
Log:
Updated comment signals to provide enough information to actually act on. This 
was uncovered when working on the documentation, which'll be committed shortly.


Modified: django/trunk/django/contrib/comments/signals.py
===================================================================
--- django/trunk/django/contrib/comments/signals.py     2008-08-26 18:53:51 UTC 
(rev 8588)
+++ django/trunk/django/contrib/comments/signals.py     2008-08-26 18:53:52 UTC 
(rev 8589)
@@ -9,13 +9,13 @@
 # discarded and a 403 (not allowed) response. This signal is sent at more or 
less
 # the same time (just before, actually) as the Comment object's pre-save 
signal,
 # except that the HTTP request is sent along with this signal.
-comment_will_be_posted = Signal()
+comment_will_be_posted = Signal(providing_args=["comment", "request"])
 
 # Sent just after a comment was posted. See above for how this differs
 # from the Comment object's post-save signal.
-comment_was_posted = Signal()
+comment_was_posted = Signal(providing_args=["comment", "request"])
 
 # Sent after a comment was "flagged" in some way. Check the flag to see if this
 # was a user requesting removal of a comment, a moderator approving/removing a
 # comment, or some other custom user flag.
-comment_was_flagged = Signal()
+comment_was_flagged = Signal(providing_args=["comment", "flag", "created", 
"request"])

Modified: django/trunk/django/contrib/comments/views/comments.py
===================================================================
--- django/trunk/django/contrib/comments/views/comments.py      2008-08-26 
18:53:51 UTC (rev 8588)
+++ django/trunk/django/contrib/comments/views/comments.py      2008-08-26 
18:53:52 UTC (rev 8589)
@@ -96,7 +96,11 @@
         comment.user = request.user
 
     # Signal that the comment is about to be saved
-    responses = signals.comment_will_be_posted.send(comment)
+    responses = signals.comment_will_be_posted.send(
+        sender  = comment.__class__,
+        comment = comment,
+        request = request
+    )
 
     for (receiver, response) in responses:
         if response == False:
@@ -105,7 +109,11 @@
 
     # Save the comment and signal that it was saved
     comment.save()
-    signals.comment_was_posted.send(comment)
+    signals.comment_was_posted.send(
+        sender  = comment.__class__,
+        comment = comment,
+        request = request
+    )
 
     return next_redirect(data, next, comment_done, c=comment._get_pk_val())
 

Modified: django/trunk/django/contrib/comments/views/moderation.py
===================================================================
--- django/trunk/django/contrib/comments/views/moderation.py    2008-08-26 
18:53:51 UTC (rev 8588)
+++ django/trunk/django/contrib/comments/views/moderation.py    2008-08-26 
18:53:52 UTC (rev 8589)
@@ -27,7 +27,13 @@
             user    = request.user,
             flag    = comments.models.CommentFlag.SUGGEST_REMOVAL
         )
-        signals.comment_was_flagged.send(comment)
+        signals.comment_was_flagged.send(
+            sender  = comment.__class__,
+            comment = comment,
+            flag    = flag,
+            created = created,
+            request = request,
+        )
         return next_redirect(request.POST.copy(), next, flag_done, 
c=comment.pk)
 
     # Render a form on GET
@@ -61,7 +67,13 @@
         )
         comment.is_removed = True
         comment.save()
-        signals.comment_was_flagged.send(comment)
+        signals.comment_was_flagged.send(
+            sender  = comment.__class__,
+            comment = comment,
+            flag    = flag,
+            created = created,
+            request = request,
+        )
         return next_redirect(request.POST.copy(), next, delete_done, 
c=comment.pk)
 
     # Render a form on GET
@@ -98,7 +110,13 @@
         comment.is_public = True
         comment.save()
 
-        signals.comment_was_flagged.send(comment)
+        signals.comment_was_flagged.send(
+            sender  = comment.__class__,
+            comment = comment,
+            flag    = flag,
+            created = created,
+            request = request,
+        )
         return next_redirect(request.POST.copy(), next, approve_done, 
c=comment.pk)
 
     # Render a form on GET

Modified: 
django/trunk/tests/regressiontests/comment_tests/tests/comment_view_tests.py
===================================================================
--- 
django/trunk/tests/regressiontests/comment_tests/tests/comment_view_tests.py    
    2008-08-26 18:53:51 UTC (rev 8588)
+++ 
django/trunk/tests/regressiontests/comment_tests/tests/comment_view_tests.py    
    2008-08-26 18:53:52 UTC (rev 8589)
@@ -102,10 +102,8 @@
 
         # callback
         def receive(sender, **kwargs):
-            self.assertEqual(sender.comment, "This is my comment")
-            # TODO: Get the two commented tests below to work.
-#            self.assertEqual(form_data["comment"], "This is my comment")
-#            self.assertEqual(request.method, "POST")
+            self.assertEqual(kwargs['comment'].comment, "This is my comment")
+            self.assert_('request' in kwargs)
             received_signals.append(kwargs.get('signal'))
 
         # Connect signals and keep track of handled ones
@@ -117,7 +115,7 @@
         # Post a comment and check the signals
         self.testCreateValidComment()
         self.assertEqual(received_signals, excepted_signals)
-
+        
     def testWillBePostedSignal(self):
         """
         Test that the comment_will_be_posted signal can prevent the comment 
from
@@ -137,7 +135,8 @@
         it gets posted
         """
         def receive(sender, **kwargs):
-            sender.is_public = False # a bad but effective spam filter :)...
+             # a bad but effective spam filter :)...
+            kwargs['comment'].is_public = False
 
         signals.comment_will_be_posted.connect(receive)
         self.testCreateValidComment()

Modified: 
django/trunk/tests/regressiontests/comment_tests/tests/moderation_view_tests.py
===================================================================
--- 
django/trunk/tests/regressiontests/comment_tests/tests/moderation_view_tests.py 
    2008-08-26 18:53:51 UTC (rev 8588)
+++ 
django/trunk/tests/regressiontests/comment_tests/tests/moderation_view_tests.py 
    2008-08-26 18:53:52 UTC (rev 8589)
@@ -48,9 +48,8 @@
 
         # callback
         def receive(sender, **kwargs):
-            flag = sender.flags.get(id=1)
-            self.assertEqual(flag.flag, CommentFlag.SUGGEST_REMOVAL)
-            self.assertEqual(flag.user.username, "normaluser")
+            self.assertEqual(kwargs['flag'].flag, CommentFlag.SUGGEST_REMOVAL)
+            self.assertEqual(kwargs['request'].user.username, "normaluser")
             received_signals.append(kwargs.get('signal'))
 
         # Connect signals and keep track of handled ones


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to