From 8aa9ecfa541649869361abc49452baf4e96082e0 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Sun, 18 Feb 2018 23:32:37 -0500 Subject: [PATCH 1/4] Updated readme with info about using bindings in celery --- README.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.rst b/README.rst index e433c14..b3cdfe7 100644 --- a/README.rst +++ b/README.rst @@ -156,6 +156,28 @@ That's it. You can now make REST WebSocket requests to the server. } } +- Bindings within asyncronous tasks using celery (Optional) + +To ensure bindings are properly connected to model instances used +within celery tasks, create a celery function to initialize the bindings +on celeryd_init.connect + +.. code:: Python + + # polls/tasks.py + from celery.signals import celeryd_init + + @celeryd_init.connect + def register_model_bindings(**kwargs): + binding = QuestionBinding + model = binding.model + + pre_save.connect(binding.pre_save_receiver, sender=model) + post_save.connect(binding.post_save_receiver, sender=model) + pre_delete.connect(binding.pre_delete_receiver, sender=model) + post_delete.connect(binding.post_delete_receiver, sender=model) + + - Add the channels debugger page (Optional) This page is helpful to debug API requests from the browser and see the From 81a9037e1a10be15438ca63c9e990111226a2615 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Sun, 18 Feb 2018 23:34:24 -0500 Subject: [PATCH 2/4] Moved readme section --- README.rst | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/README.rst b/README.rst index b3cdfe7..0058bf0 100644 --- a/README.rst +++ b/README.rst @@ -122,6 +122,29 @@ Started `__ That's it. You can now make REST WebSocket requests to the server. + +- Bindings within asyncronous tasks using celery (Optional) + +To ensure bindings are properly connected to model instances used +within celery tasks, create a celery function to initialize the bindings +on celeryd_init.connect + +.. code:: Python + + # polls/tasks.py + from celery.signals import celeryd_init + + @celeryd_init.connect + def register_model_bindings(**kwargs): + binding = QuestionBinding + model = binding.model + + pre_save.connect(binding.pre_save_receiver, sender=model) + post_save.connect(binding.post_save_receiver, sender=model) + pre_delete.connect(binding.pre_delete_receiver, sender=model) + post_delete.connect(binding.post_delete_receiver, sender=model) + + .. code:: javascript var ws = new WebSocket("ws://" + window.location.host + "/") @@ -156,28 +179,6 @@ That's it. You can now make REST WebSocket requests to the server. } } -- Bindings within asyncronous tasks using celery (Optional) - -To ensure bindings are properly connected to model instances used -within celery tasks, create a celery function to initialize the bindings -on celeryd_init.connect - -.. code:: Python - - # polls/tasks.py - from celery.signals import celeryd_init - - @celeryd_init.connect - def register_model_bindings(**kwargs): - binding = QuestionBinding - model = binding.model - - pre_save.connect(binding.pre_save_receiver, sender=model) - post_save.connect(binding.post_save_receiver, sender=model) - pre_delete.connect(binding.pre_delete_receiver, sender=model) - post_delete.connect(binding.post_delete_receiver, sender=model) - - - Add the channels debugger page (Optional) This page is helpful to debug API requests from the browser and see the From d9218bd2ff6717a7084d30ba673f463d924292eb Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Sun, 18 Feb 2018 23:35:10 -0500 Subject: [PATCH 3/4] Moved readme section --- README.rst | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/README.rst b/README.rst index 0058bf0..b3cdfe7 100644 --- a/README.rst +++ b/README.rst @@ -122,29 +122,6 @@ Started `__ That's it. You can now make REST WebSocket requests to the server. - -- Bindings within asyncronous tasks using celery (Optional) - -To ensure bindings are properly connected to model instances used -within celery tasks, create a celery function to initialize the bindings -on celeryd_init.connect - -.. code:: Python - - # polls/tasks.py - from celery.signals import celeryd_init - - @celeryd_init.connect - def register_model_bindings(**kwargs): - binding = QuestionBinding - model = binding.model - - pre_save.connect(binding.pre_save_receiver, sender=model) - post_save.connect(binding.post_save_receiver, sender=model) - pre_delete.connect(binding.pre_delete_receiver, sender=model) - post_delete.connect(binding.post_delete_receiver, sender=model) - - .. code:: javascript var ws = new WebSocket("ws://" + window.location.host + "/") @@ -179,6 +156,28 @@ on celeryd_init.connect } } +- Bindings within asyncronous tasks using celery (Optional) + +To ensure bindings are properly connected to model instances used +within celery tasks, create a celery function to initialize the bindings +on celeryd_init.connect + +.. code:: Python + + # polls/tasks.py + from celery.signals import celeryd_init + + @celeryd_init.connect + def register_model_bindings(**kwargs): + binding = QuestionBinding + model = binding.model + + pre_save.connect(binding.pre_save_receiver, sender=model) + post_save.connect(binding.post_save_receiver, sender=model) + pre_delete.connect(binding.pre_delete_receiver, sender=model) + post_delete.connect(binding.post_delete_receiver, sender=model) + + - Add the channels debugger page (Optional) This page is helpful to debug API requests from the browser and see the From d83abc3ccb04f4dba1de7ef6240c32f5bf165a52 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Sun, 18 Feb 2018 23:38:09 -0500 Subject: [PATCH 4/4] Updated readme and requirements to note support for only channels 1.x --- README.rst | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index b3cdfe7..ed00629 100644 --- a/README.rst +++ b/README.rst @@ -9,7 +9,7 @@ channels. It provides a ``ResourceBinding`` which is comparable to Django Rest Framework's ``ModelViewSet``. It is based on DRF serializer classes. -It requires Python 2.7 or 3.x, Channels >0.17.3, Django >1.8, and Django Rest Framework 3.0 +It requires Python 2.7 or 3.x, Channels 1.x > 0.17.3 , Django >1.8, and Django Rest Framework 3.0 You can learn more about channels-api from my talk at the `SF Django Meetup `__ or `PyBay 2016 `__ diff --git a/requirements.txt b/requirements.txt index 24d21fc..eec8acc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ django djangorestframework --e git+git@github.com:django/channels.git#egg=channels +-e git+git@github.com:django/channels.git@1.x#egg=channels