Skip to content
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

A method to add activity using the feed manager #23

Closed
realmhamdy opened this issue May 25, 2015 · 4 comments
Closed

A method to add activity using the feed manager #23

realmhamdy opened this issue May 25, 2015 · 4 comments

Comments

@realmhamdy
Copy link

To create my activities, I've been using the raw client.stream_client to add activities. But for them to be ready for enrichment, I'm afraid they activity data should have a specific format. Is there a method on the feed manager to do it?. I can't see it anywhere.

@tbarbugli
Copy link
Member

can you elaborate more on the data that you have in your activities? the library can handle serialization and enrichment of Django models, other object can be supported by extending the Enricher class. I can give you some concrete help once I know more about that ;) just for my curiosity, why do you need to use the stream client directly?

@realmhamdy
Copy link
Author

I used the stream client directly because I couldn't find a method on the feed manager to add activities. That was my question. Is there a method on the feed manager to add activities?.
Here's how I used the raw stream client:

user_feed = stream_client.feed("user", request.user.id)
    user_feed.add_activity({"actor": request.user.username, "verb": "publish",
                            "object": "Video:{}".format(instance.id),
                            "title": instance.title})

Since we don't maintain a model for that action, I tried to use the stream client directly to add activities.
What can work in my use case?

@tbarbugli
Copy link
Member

I think you can take advantage of the library and do something like this:

from stream_django.activity import create_reference
from stream_django.feed_manager import feed_manager


user_feed = manager.get_user_feed(request.user.id)
obj_ref = create_reference(instance)
actor_ref = create_reference(request.user) 
user_feed.add_activity({"actor": actor_ref, "verb": "publish",
                            "object": obj_ref,
                            "title": instance.title})

This is assuming that you have a Video model of course, if not please add some more information about your use case.

@realmhamdy
Copy link
Author

Thank you @tbarbugli. That worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants