ozkatz / django-announce Goto Github PK
View Code? Open in Web Editor NEWSeamlessly add realtime notifications to your existing Django project.
Seamlessly add realtime notifications to your existing Django project.
I want to use announce.js for an already written project in django and using mysql. I am using announce.js for the notifications. As I can see current implementation would require auth data to be in redis store. I was thinking as an enhancement to be able to use auth data from other db's and use redis store for notifications only. Would that make sense. I am not sure but I almost have some code written for this
inside AnnounceCookieMiddleware.process_response(), I saw a line calling
response.user.is_authenticated which calls
from django.contrib.auth import get_user
request._cached_user = get_user(request)
->
104 -> def get_user(request):
105 from django.contrib.auth.models import AnonymousUser
106 try:
107 user_id = request.session[SESSION_KEY]
108 backend_path = request.session[BACKEND_SESSION_KEY]
109 backend = load_backend(backend_path)
110 user = backend.get_user(user_id) or AnonymousUser()
"backend" here is 'django.contrib.auth.backends.ModelBackend'. Thus, "backend.get_user(user_id)" calls
->
61 def get_user(self, user_id):
62 try:
63 return User.objects.get(pk=user_id)
64 except User.DoesNotExist:
65 return None
which seems like a blocking call to mysqldb.
Is there a setting / backend that I am missing? I thought using node.js (which is async server) requires ( if we want to use async features..) non-blocking db calls...
Please tell me I'm wrong... I think this app is amazing except those lines, and I really want to use this in my project.
Now I am thinking of writing a session sharing middleware (or just use django-redis-sessions) to let node.js read session info from redis.
There is no simplejson after 1.6 or 1.5
Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/home/coldfusion/skworkspace/virtual_notification/local/lib/python2.7/site-packages/django/core/management/init.py", line 338, in execute_from_command_line
utility.execute()
File "/home/coldfusion/skworkspace/virtual_notification/local/lib/python2.7/site-packages/django/core/management/init.py", line 312, in execute
django.setup()
File "/home/coldfusion/skworkspace/virtual_notification/local/lib/python2.7/site-packages/django/init.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/coldfusion/skworkspace/virtual_notification/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/coldfusion/skworkspace/virtual_notification/local/lib/python2.7/site-packages/django/apps/config.py", line 86, in create
module = import_module(entry)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/home/coldfusion/skworkspace/virtual_notification/local/lib/python2.7/site-packages/announce/init.py", line 4, in
from django.utils import simplejson as json
ImportError: cannot import name simplejson
Hi, I write this issue, because I followed what the README told about how to configure Announce, but it seems not to work.
I paste here my base.html
head:
{% load announcetags %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
{% announce_js %}
<script src="/apps/site/bower_components/lodash/dist/lodash.js"></script>
<script src="/apps/site/bower_components/angular/angular.js"></script>
<script src="/apps/site/bower_components/restangular/dist/restangular.js"></script>
<script src="/apps/site/bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="/apps/site/js/app.js"></script>
<script src="/apps/site/js/controllers.js"></script>
<script type="text/javascript">
// use .on() to add a listener. you can add as many listeners as you want.
announce.on('notifications', function(data){
alert("Notification received");
console.log("Notification received");
}).init();
// .init() will authenticate against the announce.js server, and open the WebSocket connection.
console.log("Announce.js inited");
</script>
</head>
here my viewset
in Django:
class WordViewSet(viewsets.ModelViewSet):
queryset = Word.objects.all()
serializer_class = WordSerializer
def post_save(self, obj, created=False):
if created:
print 'OBJECT CREATED'
announce_client.broadcast('notifications', data={'msg': obj.word})
and here my settings.py
(the interesting part):
MIDDLEWARE_CLASSES = (
'announce.middleware.AnnounceCookieMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ANNOUNCE_CLIENT_ADDR = 'localhost:5500'
ANNOUNCE_API_ADDR = 'localhost:6600'
ANNOUNCE_HTTPS = False
I also added a settings.json
file to use the local memory instead of redis:
{
"storage": "mem"
}
And that's it.
I tun the server with node server.js --config=settings.json
I expect an alert when i POST a new word, but nothing happens.
Thank you in advance
In your documentation you have:
ANNOUNCE_CLIENT_ADDR - defaults to 'localhost:5500'. should probably be changed for production.
What should this be changed to for production?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.