2

I am currently in the process of implementing a Django based peer to peer quizzing system wherein a user can challenge another user for a quiz.(Much like quizup). I have implemented nearly all the major components of it and the last remaining one is in-website user notification - wherein the user is able to see the number of new unresponded challenges to him.

Django-notification, it seems , uses email based notification,but I want to notify the user within the website itself - just like StackOverflow has for unread notifications/messages, the user will be able to see the number of active challenges under a challenges tab. It need not be real-time like StackOverflow though.

Have extensively Googled,but failed to find a solution.

Any help would be appreciated.

404
  • 97
  • 3
  • 12

2 Answers2

1

If you want a delayed sort of update, have a JavaScript setinterval call that repeats an Ajax call to a view to check notifications.

For instance, in your base template, have something like this (using jQuery)

function checkNotifications() {
    $.get("url", function(data) {
            // do something with the data
        }
    });
}
setInterval(checkNotifications, 30000);

to check notifications every 30 seconds.

WebSockets can be used for a live update mechanism. I haven't used websockets with Django, but this project looks active and was top on my Google search.

Celeo
  • 5,583
  • 8
  • 39
  • 41
  • For the moment,not looking at a live update,delayed update is fine. – 404 Apr 02 '15 at 20:32
  • So I will need to create a specific url handler to send the ajax request to which checks if this user has received a new challenge,and also under the Challenges model,implement read/unread boolean property and take a count of it right? – 404 Apr 02 '15 at 20:33
  • I am wondering how Stackoverflow does it ? (Hypothetically assuming it is not real time and is delayed) – 404 Apr 02 '15 at 20:45
  • Websockets. In Chrome, you can open up the dev tools and see the websocket connection in the Network tab. – Celeo Apr 02 '15 at 20:48
0

Not sure if you want this more standard/simple type of flow, but here goes:

in view,

Assuming you have an @login_required already to establish the user has logged in

1) return the queryset for the quizzes that the use is or has participated in 2) filter on unresponded challenges based on your options, finished etc e.g.

unresponded = all_games.filter(status='unresponded')

3) send all of the different context of the different games you want to show (inlcuding unresponsed) via the render to your page that you want

return render(request, "games.html", context)

4) show the games in your games.html page.

ivan7707
  • 1,146
  • 1
  • 13
  • 24
  • Yes that is what I am planning to do Ivan. Will try to do it. – 404 Apr 02 '15 at 20:43
  • @404, I'll try to help if you have any more questions. I saw a good implementation of this type of thing, I'll see if I can find the code later tonight – ivan7707 Apr 02 '15 at 20:48
  • Ivan,thanks a lot. It would be great if you could share the code. – 404 Apr 02 '15 at 20:50
  • @404, sorry, couldnt find that particular code, but if you ask a q, I'll try to help. That said, I think learning the websockets approach would be great for the user. – ivan7707 Apr 03 '15 at 01:10