django
Javascript push notifications with Django & Pusher
I've been running into an increasing need for JS push notifications and have played with a few ways of doing it. Recently ran across Pusher API. They use a combo of HTML5 websockets & flash fallbacks. Much easier than Comet, etc.
But their python library didn't support presence. Here's everything you need to make presence work in Django, including an updated library.
My JS
var pusher = new Pusher('MY_PUBLIC_KEY');
Pusher.channel_auth_endpoint = '/api/pusher/auth/'
var channel = pusher.subscribe('presence-meeting-1')
Django dump & restore database
# dump data to send to receiving host
./manage.py dumpdata > fixtures/all.json
# in mysql on receiving host
mysql -uUSER -pPASS DATABASE_NAME;
drop database DATABASE_NAME;
create database DATABASE_NAME;
exit;
# @ shell on receiving host
./manage.py syncdb
# in mysql on receiving host
mysql -uUSER -pPASS DATABASE_NAME;
delete from auth_permission; delete from django_admin_log; delete from django_content_type;
# @ shell on receiving host
./manage.py loaddata fixtures/all.jsondebugging email with django
an easy way to get django to send emails direct to stdout ( and avoid connection refused errors )
in settings.py:
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025and at a shell:
python -m smtpd -n -c DebuggingServer localhost:1025 Quickly starting django development server on local IP
I am frequently running ./manage.py runserver SOME_IP:8000 , so I can run django dev on my local IP address, so it can be accessed by other computers on the network for testing. Here's a shell script to automate the steps it takes to do that:
#!/bin/bash
# virtualenv
source bin/activate
# get the local IP
IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;
# write the IP for use in settings module
echo "IP='$IP'" > local_settings_ip.py
# launch window in firefox ( will need to refresh )
firefox http://$IP:8000
multiple versions of django with virtualenv for dummies
It's easy to run multiple versions of django for python development. Let's say you already have an existing django project in a directory called "chat", but it needs a different django version than the one installed globally on your machine.
# get dependency package
sudo apt-get install python-virtualenv
# set up a new virtual environment for the "chat" directory
virtualenv --no-site-packages chat
cd chat
# create a requirements.txt file that will list the python modules you need, eg
nano requirements.txt
# use pip to install the packages