Skip to content

Latest commit

 

History

History
113 lines (73 loc) · 4.66 KB

README.rst

File metadata and controls

113 lines (73 loc) · 4.66 KB

tracker_project

A simple Django project to report and track geo-located incidents within certain areas of interest. Whenever a new incident occurs the user is reported in real-time and the event is marked in a map (using Google Maps JavaScript API). It's is possible to report the locations manually, but there's also a view that uses the geolocator library to automatically detect the user's location.

This project created to demonstrate how to use GeoDjango and send real-time notifications using gevent-socketio and RabbitMQ. For an in depth description of the project see the following blogpost.

The default configuration uses PostgreSQL with the PostGIS extensions as database back-end, but it can also work with other GeoDjango compatible databases like SQLite + SpatiaLite.

Update #2

I've created yet another implementation of the project using Django channels for the real-time notifications. You can check it out in the use-django-channels branch.

Update

Some people asked me about a Node.js+socket.io (instead of the gevent-socketio) implementation of the project, so I created a node_js branch for it.

Requirements

Before you can run this project, the following packages need to be installed:

Ubuntu

  • python-dev
  • postgresql
  • postgresql-server-dev-all
  • postgis
  • python-virtualenv
  • libevent-dev
  • rabbitmq-server

Fedora

  • python-devel
  • postgresql-server
  • libpqxx-devel
  • postgis
  • python-virtualenv
  • libevent-devel
  • rabbitmq-server

Installation

Clone the repository:

$ git clone git@github.com:abarto/tracker-project.git

Create and activate the virtual environment:

$ cd tracker-project/
$ virtualenv venv/
$ . venv/bin/activate

Install the requirements:

(venv)$ pip install -r requirements.txt

Initialize nodeenv, and install bower:

(venv)$ nodeenv -p
(venv)$ npm install -g bower

Create the database and the database user, install the PostGIS extensions:

$ sudo -u postgres psql
postgres=# CREATE ROLE tracker_project LOGIN PASSWORD 'tracker_project' NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
postgres=# CREATE DATABASE tracker_project WITH OWNER = tracker_project;
postgres=# \connect tracker_project;
postgres=# CREATE EXTENSION postgis;

Initialize the database and set-up the Django environment:

(venv)$ cd tracker_project/
(venv)$ python ./manage.py migrate
(venv)$ python ./manage.py bower_install

At this point it is possible to run the development server by using the special socketio_runserver management command

(venv)$ python ./manage.py socketio_runserver

If you want to run in it in a production environment. Follow the instructions of the next section.

Running the application

The application can be run using Chaussette, with the socketio backend:

(venv)$ chaussette --backend socketio --port 8000 tracker_project.wsgi.application

Please notice that the application won't server the static files, so before you can start using it, you need to run the collectstatic management command:

(venv)$ python ./manage.py collectstatic

and then use a regular HTTP server like nginx (we've included a sample configuration file) to server the files.

You can also use socket and process managers like Circus or Supervisor.

Vagrant

A Vagrant configuration file is included if you want to test the project.

Acknowledgements

The basic architecture for the notifications system follows the guidelines presented by Jeremy West in the blogpost Django, Gevent, and Socket.io. We also used the code for his socketio_runserver management command.