New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

action_handler should check for actor, verb *and* target #2

Closed
JordanReiter opened this Issue Mar 31, 2010 · 2 comments

Comments

Projects
None yet
3 participants
@JordanReiter

JordanReiter commented Mar 31, 2010

Right now, action_handler uses
activity = Activity.objects.get_or_create(
actor_content_type = ContentType.objects.get_for_model(actor),
actor_object_id = actor.pk,
verb = verb
)[0]
however, this means that if an actor performs the same verb with different targets, only one instance for that actor and verb is saved.

Here's the changes:
diff --git a/actstream/models.py b/actstream/models.py
old mode 100644
new mode 100755
index 17e894f..a04e58e
--- a/actstream/models.py
+++ b/actstream/models.py
@@ -153,14 +153,19 @@ model_stream.doc = Activity.objects.stream_for_model.doc

 def action_handler(verb, target=None, **kwargs):
     actor = kwargs.pop('sender')
-    activity = Activity.objects.get_or_create(
-        actor_content_type = ContentType.objects.get_for_model(actor),
-        actor_object_id = actor.pk,
-        verb = verb
-    )[0]
     if target:
-        activity.target_object_id = target.pk
-        activity.target_content_type = ContentType.objects.get_for_model(target)
-        activity.save()
+        activity = Activity.objects.get_or_create(
+            actor_content_type = ContentType.objects.get_for_model(actor),
+            actor_object_id = actor.pk,
+            target_object_id = target.pk,
+            target_content_type = ContentType.objects.get_for_model(target),
+            verb = verb
+        )[0]
+    else:
+        activity = Activity.objects.get_or_create(
+            actor_content_type = ContentType.objects.get_for_model(actor),
+            actor_object_id = actor.pk,
+            verb = verb
+        )[0]
@marcinn

This comment has been minimized.

Show comment
Hide comment
@marcinn

marcinn Apr 5, 2010

I confirm that issue. Also I think there is no needs for using get_or_create() on Action. Simply create() call should be fine.

marcinn commented Apr 5, 2010

I confirm that issue. Also I think there is no needs for using get_or_create() on Action. Simply create() call should be fine.

@justquick

This comment has been minimized.

Show comment
Hide comment
@justquick

justquick Apr 5, 2010

Owner

thanks for the patch, this has been fixed in the most recent revision. in the future, please fork and submit a pull request

Owner

justquick commented Apr 5, 2010

thanks for the patch, this has been fixed in the most recent revision. in the future, please fork and submit a pull request

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment