Skip to content

1stvamp/flask-straw-poll

Repository files navigation

flask-straw-poll

Example straw poll Flask app

UK Parliament constituency data

This app requires area data in the format:

{
  "id": { "name": "Placename" }
}

It was developed with Westminster Constituency data freely available from mapit.mysociety.org (under the terms of the OS OpenData license and the Open Government License).

You can either create your own data set under ./flask_straw_poll/data/wmc.json, copy the example data from ./flask_straw_poll/data/wmc.json.example, or download it from mapit:

$ cd flask-straw-poll
$ curl http://mapit.mysociety.org/areas/WMC -o flask_straw_poll/data/wmc.json

$ # Or use the example data
$ cp flask_straw_poll/data/wmc.json.example flask_straw_poll/data/wmc.json

Quick bootstrap script

To get up and running with the demo quickly there is a bootstrap shell script which creates a virtualenv, installs the dependencies, downloads constituency data, creates the DB models in a local sqlite3 file, creates some test data, and copies the example config file to `config.json`:

$ cd flack-straw-poll
$ ./bootstrap.sh
Getting WMC data from mapit.mysociety.org..
 [snip]

Setting up venv..
 [snip]

Installing requirements..
 [snip]

Creating DB models..
 [snip]

Creating test data (parties, votes)..
 [snip]

Copying config.json.example -> config.json
Done.

Installation

The preferred way to install the app is via pip:

$ pip install flask-straw-poll

Or manually using a checkout of the code with pip inside a virtualenv

$ cd flask-straw-poll
$ virtualenv --no-site-packages ./venv
$ source ./venv/bin/activate
$ pip install -r requirements.txt

Usage

To make quickly using the demo app faster (without setting up a WSGI serving env etc.) you can use the runserver script once all the depenencies, config and data are installed/in-place:

$ cd flask-straw-poll
$ python flask_straw_poll/runserver.py
 * Running on http://127.0.0.1:5000/
 * Restarting with reloader

Note: If you installed the app as an egg via pip above, then you can use the CLI command straw-poll-run to invoke the runserver script.

You can then access the app in a browser via 127.0.0.1:5000.

You should see something like:

image

Tests

A functional testsuite is provided in tests.py and can be run directly inside your venv with python tests.py.

About

Example straw poll Flask app

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published