Django notify user about an event and require a response - django

I am developing a food ordering web app with Django.
When a user submits an order, i want the restaurant to be notified about this order and either accept it or reject it. In both cases, i need to notify the user if his order was accepted or not. I've come across django notifications and django channels but i don't know which one i should choose.
Any help would be appreciated. Thank you!

I would say django-channels is more suitable when you need to have a high iteration between your backend and frontend (like a chat or some real-time like geolocation position for deliveries)
django-notifications seems more suitable for your propose, when you need to open communication (often) async with your frontend to notify some backend change like some finished task, or some background change

Related

Is there a way to send push notifications with Django

Hello I wonder is there a way to send push notifications with Django to a user.
I have a website that accepts/refuses vacation demands.
When a user sends a vacation demand my Django app sends email to the CEO to notify him that there was a new vacation request.
When the CEO accepts the demand it sends email to the user that the demand was accepted.
But since the CEO receives plenty of emails a day and he barely sees my emails i would like to make a browser notification whenever he opens the browser to see notification from my website that a demand is waiting to be approved/refused.
Is there a library that can do that for me,
I've tried django-webpush but I couldn't managed it to work even though I
followed all the steps.
Yes you can, since your have the information that your user accessed your server at least once. checkout this lib
https://github.com/jazzband/django-push-notifications
EDIT Gonna put more information about it
If you expect receive one response from your backend to your backend you can write some watcher to receive new data, or create one plugin, or use sockets or even make your frontend send one call to backend with some interval time to check if there is any new messages...
Lets split up a bit
1 - Watcher
Using watchers you can just watch your backend to any changes... build it from scratch i thing i a bit "hard", you can use some modern frontend framework that already have it like Angular, React, Vue... and capture new incomes messages from your backend and create Notification instance in your browser and your it to your user (i guess they will have to keep the page openned to do it... im not 100% sure)
2 - Plugins
You can build one plugin to add to your browser and receive the data from your server... since you already in browser is more easier to use browser functions
3 - Sockets
The common way to make 2 ways comunication from frontend to backend, most used with chats and things arround that, just create one channel of communications between this 2 sides and you will be able to send and receive messages from frontend or backend
4 - Dirty Way
If you not get the time to implement it like supposed to do with quality you can go the dirty way, just setup one ajax in your page to check your backend to new messages every 5 minutes? or more or less... and if find any new data (of course you will have to handle it on your backend like any other suggestions above) and then you create one new notification in your browser and show to your user...
Im sure there is bunch of libs that already do most of things to you, so just search a bit and test until you find anything that fits your need

Send a post request to server

I am fairly new in web development and I decided to handle a user's availability to send a POST request to server. However, I do not know even whether it is possible or not but when a user close my Django site without using logout button (For example close the browser or tab), in order to understand the user is offline or online, I want to send a request to server. As a result, when the server does not get an answer from the user for a while, it automatically logout the user.
Can you tell me is it a good way to handle a user's availability and first of all is it a realistic solution? If it is, can you suggest me a document or example that helps me please.
I agree to to the answer of #Mounir. That's not related to django, if you want to know when a user is "disconnected"(close the tab or window) you need to use javascript, in concrete you need to use Sockets.
I recommend you this ones:
http://socket.io/
https://github.com/centrifugal/centrifugo
I'm using centrifugo for one project right now. In concrete, for chat and inbox messaging. It's very simple to make it run with Django.
Greetings
For logging out user you can use the Session expiration, but for all other staff you want to achieve I don't see any thin really related to Django itself, everything depend on your requirements and is more Browser/javascript related than Django.

What scaleable way to send notification emails in django?

On a custom django app I'd like to send notification email on many events, e.g. when a user's comment is being liked or comment is posted on her profile.
However I am worried that this will have scaling implications for the app so I am wondering what is the best way to do it so that it does not block the views.
Use Django-Celery to put it in a Task Queue, that way it all happens in the background.
http://celery.readthedocs.org/en/latest/django/first-steps-with-django.html
Here is a good video link on how to use Celery with Django:
https://godjango.com/63-deferred-tasks-and-scheduled-jobs-with-celery-31-django-17-and-redis/

Facebook like notification updates using django signal or notification

How can i use django-notifications or django-signals to make something like facebook updates notification that shows in the user profile if any other user likes or posts comments on user's blog or posts?
For the activity feed, we use https://github.com/justquick/django-activity-stream Documentation: http://justquick.github.com/django-activity-stream/
For the js widget and live notifications, we use https://github.com/subsume/django-subscription yourlabs example, it depends on redis but you can easily add a model backend if you really want to. Redis is a good choices it's half a megabyte of dependency. Documentation: http://django-social.rtfd.org
There is no application that does meta-notifications ("notification groupping") properly but a lot of research has been done. Basically you need another app, with a MetaNotification model, and something (management command, signal ...) that will visit notifications and create MetaNotification instances. Then you should display MetaNotification lists rather than Activity or notification list.
Finnaly, if you want configurable email notifications then you can use django-notifications: https://github.com/jtauber/django-notification or this app which looks nicer: http://www.tomaz.me/django-notifications/
I'm not aware of any app that does it all. It is going to be some work for you.
"It's a long way to the top if you wanna rock'n'roll" or as I like to say "patience and perseverance" :)
https://pypi.python.org/pypi/feedly allows you to build newsfeed and notification systems using Cassandra and/or Redis. Examples of what you can build are applications like the Facebook newsfeed, your Twitter stream or your Pinterest following page.

Django refresh page if change data by other user

I have a test django app.
In one page the test show the same question to all users.
I'd like that when a user answers correctly, send a signal to other active user's browser to refresh to the next question.
I have been learning about signals in django I learning work with them but I don't now how send the "refresh signal" to client browser.
I think that it can do with a javascript code that check if a certain value (actual question) change and if change reload the page but I don't know this language and the information that I find was confused.
Can anybody help me?
Many Thanks.
There is no existing way to send a event from server to browser. But you can get your web page polling your server periodically (say every 5 seconds).
The code in javascript/jquery could be like the following
setInterval(function(){
$.post("your_ajax_handler_url/is_answerd", userId, function(xhr){
if(xhr.responseText == "answered"){
location.reload(true);
}
}
}, 5000);
That is not at all what signals in Django are for. Signals in django are server side hooks that allow you perform tasks on the server when a certain even happens.
To 'send a refresh' to the browser, you need to use a server-push approach such as Comet. Alternatively you can get your clients to periodically poll the server to look for update.
Here's some links:
How to implement Server push / long polling / comet using PHP and Javascript
How do I implement basic "Long Polling"?
What you need are coment(http://en.wikipedia.org/wiki/Comet_%28programming%29) and tornado(http://www.tornadoweb.org/)