Ekratia’s documentation!

Ekratia is a new way of making democracy. Members of Ekratia use the Internet to vote directly for new ideas and laws. In case they are too busy to vote, members can delegate their vote to other members. Members can change their delegates on real time.

Contents:

Installation

Clone the Ekratia repository:

$ git clone git@github.com:ekratia/ekratia.git

This project was created using cookiecutterdjango_

Setup project locally

The steps below will get you up and running with a local development environment. We assume you have the following installed:

  • pip
  • virtualenv
  • PostgreSQL

First make sure to create and activate a virtualenv, then open a terminal at the project root and install the os dependencies:

$ sudo ./install_os_dependencies.sh install

Then install the requirements for your local development:

$ pip install -r requirements/local.txt

Then, create a PostgreSQL database with the following command. We will call the database ekratia

$ createdb ekratia

You can now run the usual Django migrate and runserver command:

$ python manage.py migrate

$ python manage.py runserver

Live reloading and Sass CSS compilation

If you’d like to take advantage of live reloading and Sass / Compass CSS compilation you can do so with the included Grunt task.

Make sure that nodejs is installed. Then in the project root run:

$ npm install

Now you just need:

$ grunt serve

The base app will now run as it would with the usual manage.py runserver but with live reloading and Sass compilation enabled.

To get live reloading to work you’ll probably need to install an appropriate browser extension

Run Unit Tests

python manage.py test

Front-end Application

We use bower to manage the Front-end dependencies. The project already has a compiled and minified version of the dependencies. So you only need to run it when adding new dependencies.

npm -g install bower
bower install

Path of front-end libraries: /bower_components

API

API endpoints used in the Ekratia application to be consumed inside the application.

The endpoints are located inside /api/v1/<endpoint>

Users

Conversations

Delegates

Referendums

Graphs

Ekratia uses Networkx library to operate with graphs. GraphEkratia is a class that extends from DiGraph and implements required methods for the Ekratia vote system.

Users

Application in charge to handle all the information and methods of the users.

Models

Views

Delegates

Models

Views

Referendums

Models

Views

Conversations

Models

Views

Settings

This project relies extensively on environment settings which will not work with Apache/mod_wsgi setups. It has been deployed successfully with both Gunicorn/Nginx and even uWSGI/Nginx.

For configuration purposes, the following table maps environment variables to their Django setting:

Environment Variable Django Setting Development Default Production Default
DJANGO_ADMIN_URL n/a r’^admin/’ raises error
DJANGO_CACHES CACHES (default) locmem redis
DJANGO_DATABASES DATABASES (default) See code See code
DJANGO_DEBUG DEBUG True False
DJANGO_SECRET_KEY SECRET_KEY CHANGEME!!! raises error
DJANGO_SECURE_BROWSER_XSS_FILTER SECURE_BROWSER_XSS_FILTER n/a True
DJANGO_SECURE_SSL_REDIRECT SECURE_SSL_REDIRECT n/a True
DJANGO_SECURE_CONTENT_TYPE_NOSNIFF SECURE_CONTENT_TYPE_NOSNIFF n/a True
DJANGO_SECURE_FRAME_DENY SECURE_FRAME_DENY n/a True
DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS HSTS_INCLUDE_SUBDOMAINS n/a True
DJANGO_SESSION_COOKIE_HTTPONLY SESSION_COOKIE_HTTPONLY n/a True
DJANGO_SESSION_COOKIE_SECURE SESSION_COOKIE_SECURE n/a False
DJANGO_DEFAULT_FROM_EMAIL DEFAULT_FROM_EMAIL n/a “your_project_name <noreply@your_domain_name>”
DJANGO_SERVER_EMAIL SERVER_EMAIL n/a “your_project_name <noreply@your_domain_name>”
DJANGO_EMAIL_SUBJECT_PREFIX EMAIL_SUBJECT_PREFIX n/a “[your_project_name] “
DJANGO_ALLOWED_HOSTS ALLOWED_HOSTS [‘*’] [‘your_domain_name’]

Deployment

This project relies on Environment variables.

Please make sure you define the variables according to the Settings page:

Deployment to Production on AWS

System requirements for Debian based servers: requirements.apt

Python requirements: requirements.txt

It was succesfully tested and mounted on AWS using Python Virtualenv, UWSGI and NGINX.

UWSGI Configuration

[uwsgi]
vhost = true
plugins = python
socket = /tmp/ekratia.sock
master = true
enable-threads = true
processes = 4
wsgi-file = /srv/apps/ekratia/config/wsgi.py
virtualenv = /home/ubuntu/.virtualenvs/env
chdir = /srv/apps/ekratia/

Nginx Configuration

server {
    listen 80;
    access_log /var/log/nginx/ekratia.access.log;
    error_log /var/log/nginx/ekratia.error.log;

    location / {
        uwsgi_pass      unix:///tmp/ekratia.sock;
        include     uwsgi_params;
    }
}

The used services were:

Amazon EC2
Amazon RDS PostgresSQL
Amazon S3

Indices and tables