I just started trying Django-announce for the realtime notification
Here is my basic view to check this application
@login_required
def first_profile(request):
hi = {}
user = User.objects.get(username = request.user.username)
user_current = FullProfile.objects.get(user_id = user.id)
if request.POST:
user_current.first_name = request.POST['first_name']
try:user_current.middle_name = request.POST['middle_name']
except:pass
user_current.last_name = request.POST['last_name']
try:user_current.gender = request.POST['gender']
except:pass
try:user_current.profession = request.POST['profession']
except:pass
user_current.save()
tags = Tags.objects.all()
category = Category.objects.all()
cn = Country.objects.all()
st = State.objects.all()
hi['user'] = user
hi['con'] = cn
hi['State'] = st
hi['tags'] = Tags
hi['cuser'] = user_current
hi['category'] = category
announce_client.emit(
user.id,
'notifications',
data={ 'msg' : 'This user is already regsitered ' }
)
return render_to_response('COD/dashboard.html',hi,context_instance=RequestContext(request))
I already imported .
from announce import AnnounceClient
announce_client = AnnounceClient()
In the view
On dashboard.html
{% load announcetags %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Consult On Demand</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="{{MEDIA_URL}}css/bootstrap.css">
<link rel="stylesheet" href="{{MEDIA_URL}}css/bootstrap-responsive.css">
<link rel="stylesheet" href="{{MEDIA_URL}}css/jquery.fancybox.css">
<link rel="stylesheet" href="{{MEDIA_URL}}css/style.css">
<script src="{{MEDIA_URL}}js/jquery.js"></script>
<script src="{{MEDIA_URL}}js/less.js"></script>
<script src="{{MEDIA_URL}}js/bootstrap.min.js"></script>
<script src="{{MEDIA_URL}}js/jquery.peity.js"></script>
<script src="{{MEDIA_URL}}js/jquery.fancybox.js"></script>
<script src="{{MEDIA_URL}}js/jquery.flot.js"></script>
<script src="{{MEDIA_URL}}js/jquery.color.js"></script>
<script src="{{MEDIA_URL}}js/jquery.flot.resize.js"></script>
<script src="{{MEDIA_URL}}js/jquery.cookie.js"></script>
<script src="{{MEDIA_URL}}js/jquery.cookie.js"></script>
<script src="{{MEDIA_URL}}js/custom.js"></script><script src="js/demo.js"></script>
{% announce_js %}
</head>
<body>
<script>
announce.on('notifications', function(data){
alert(data.msg);
});
announce.init();
</script>
</body>
</html>
I installed announe in my Installed app and added corresponding middleware .
I am running announce server like
node node_modules/announce.js/server.js
I don't know what might i am doing wrong I am expecting alert message in first_profile view .
Please help me Where and what i am doing wrong here