This tutorial is a work in progress.
Install PostgreSQL and Python 3.4.x. Optionally install pyenv, virtualenv, etc. to manage python environments.
Install Django and the PostgreSQL database adapter.
$ pip install Django
$ pip install psycopg2Create login role.
CREATE ROLE leaderboard_django LOGIN
PASSWORD 'leaderboard_django'
NOSUPERUSER INHERIT CREATEDB NOCREATEROLE NOREPLICATION;Create database.
CREATE DATABASE leaderboard_django
WITH OWNER = leaderboard_django
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'en_US.UTF-8'
LC_CTYPE = 'en_US.UTF-8'
CONNECTION LIMIT = -1;Create table structure.
$ python manage.py migrate$ python manage.py runserverHit the server in your browser at http://localhost:8000/. It will immediately redirect to the company leaderboard for the fictitious company "Vandalay Industries".
In your browser javascript console, add scores to leaderboard:
window.leaderboard.add({name: 'George Costanza', score: 10});
window.leaderboard.add({name: 'Elaine Benes', score: 105});You can also add more than one employee at a time by passing an array of
objects to leaderboard.add().
window.leaderboard.add([{name: 'Jerry Seinfeld', score: 110},{name: 'Cosmo Kramer', score: 100}]);Note that you are adding scores to the leaderboard, not updating the score value. If we add another 10 "points" to Kramer, his score updates to 110.
window.leaderboard.add({name: 'Cosmo Kramer', score: 10});The leaderboard object updates the scores on the server and emits
events for leaders who were added or updated along with their new total
score.
The template application comes with 3 models and a couple of really simple views and actions to update those models.
Company is the root object for any organization and its leaderboard.
We identify companies by a uid field (which doubles as name in the
"Vandalay Industries" example.)
Leader is a person that belongs to a company, and a company can have
many leaders.
Score is a number and a timestamp that belongs to a leader. A leader
can have many scores over time. Additionally, scores can have an
arbitrary category.
In this example, the category is hard-coded in a few places to "close" so that we create a leaderboard of "closers." Coffee is for closers.
TODO
TODO
TODO