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

Example of subscribing to an event w/ channels #84

Open
lowegreg opened this issue Nov 1, 2018 · 3 comments
Open

Example of subscribing to an event w/ channels #84

lowegreg opened this issue Nov 1, 2018 · 3 comments

Comments

@lowegreg
Copy link

lowegreg commented Nov 1, 2018

I know this isn't an actual issue, but wondering if anyone has a sample that includes how to setup events and then allow uses to subscribe/unsubscribe to them.

Cheers,
Greg

@benjaoming
Copy link
Member

Yup, it's the test project in the root of the repo:

https://github.com/django-wiki/django-nyt/tree/master/test-project

@lowegreg
Copy link
Author

lowegreg commented Nov 3, 2018

Thanks for the reply. I was looking for something a bit more explicit. In case anyone else stumbles across this post, below is the code I wrote to subscribe to an content type and then send a message. In this case they are based around projects. Use or ignore as you see fit...

#Send welcome notification
from django.utils.translation import ugettext as _
from django_nyt.utils import notify, subscribe
from django_nyt.models import Settings
from django.contrib.contenttypes.models import ContentType

user = User.objects.get(id = userID)
ct = ContentType.objects.get(model="project")
settings = Settings.get_default_setting(user)
sendUsers = User.objects.filter(id = userID)

EVENT_KEY = "project_"+str(projectID)
subscribe(settings, EVENT_KEY, ct)
notify(_("You have been added to the " + EVENT_KEY + " project."), EVENT_KEY, None, "/project/"+str(projectID)+"/projectsummary/", {}, sendUsers)

@benjaoming benjaoming changed the title Test-App example of subscribing to an event Example of subscribing to an event w/ channels Nov 3, 2018
@benjaoming
Copy link
Member

@lowegreg there is a bit of documentation examples for invoking notify() but perhaps an example for creating a settings object, a subscription and a final notification would be nice to have in the documentation.

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

No branches or pull requests

2 participants