mozilla / teach-api

A basic API to store data for learning.mozilla.org
2 stars 11 forks source link

Build Status Shipping fast with zenHub

This is a backend data store with a REST API for use by the teach website.

Requirements

Quick Start

virtualenv venv

# On Windows, replace the following line with 'venv\Scripts\activate'.
source venv/bin/activate

pip install -r requirements.minimal.txt
python manage.py syncdb

You will be asked if you want to create an administrative user. Respond affirmatively, fill out the details, and then run:

python manage.py initgroups
python manage.py runserver

If you are running the Teach-API in a VM, and you wish to access the Django instance from outside the VM, you will need to have your VM use bridged networking (to make it part of your preexisting local network) and then use the following runserver command:

python manage.py runserver 0.0.0.0:8000

You can then access the server from the host machine on the VM's IP address. For example, if the VM has an IP 192.168.1.1, the host machine can access the teach-api via http://192.168.1.1:8000

Making a "staff" account, to use the admin route

In order to use the admin route, you will need to clear a user account by ensuring is_staff = 1. If the webmaker login username that you want to use is the same as the administrative user, you're done. Otherwise, after signing in with your webmaker user account once, connect to the db.sqlite3 database file in the teach-api root directory with a sqlite3 CLI or GUI (SQLite Manager for Firefox is highly recommended for working with Sqlite files), and update the auth_users table, by setting the user record associated with your webmaker account to have is_staff set to 1 rather than 0.

You should now be able to load up the administrative view for the teach-api via http://localhost:8000/admin when logged in with your webmaker account.

Environment Variables

Unlike traditional Django settings, we use environment variables for configuration to be compliant with twelve-factor apps.

Note: When an environment variable is described as representing a boolean value, if the variable exists with any value (even the empty string), the boolean is true; otherwise, it's false.

Note: When running manage.py, the following environment variables are given default values: SECRET_KEY, PORT, ORIGIN. CORS_API_LOGIN_ORIGINS. Also, DEBUG is enabled.

Deprecated Environment Variables

These will be removed at some point.

Deployment

It's assumed that production deploys (i.e. where DEBUG is false) are hosted over https. The site will not work if it is hosted on production over http.