brew install python
. This also installs pip.pip install virtualenv
pip install virtualenvwrapper
brew install postgres@9.6
. IMPORTANT: Read what brew tells you. You might want to make start postgresql at login ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
and then load postgresql now with launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
.brew install postgis
brew doctor
if desired.git clone https://github.com/greenstreetsinitiative/checkin2015.git
OR fork (via the Github website) and clone your fork.initdb /usr/local/var/postgres -E utf8
createuser -d -P postgres
creates a role that can make databases.pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start &
if the server is not already running.createuser django
createdb -O django checkin
psql -d checkin -c "ALTER USER django WITH PASSWORD 'django';"
psql -d checkin -c "CREATE EXTENSION postgis;"
mkvirtualenv greenstreets
. You can name it other than greenstreets too.export SECRET_KEY="abcdef"
export DB_NAME="checkin"
export DB_USER="django"
export DB_PASSWORD="django"
export DB_PORT="5432"
export DB_HOST="localhost"
export EMAIL_HOST_USER="xten"
export EMAIL_HOST_PASSWORD="xten"
export MANDRILL_API_KEY="V62ndycapG44sI-x9EcG1A"
workon greenstreets
. This activates the virtual environment.pip install -r requirements.txt
python manage.py migrate
python manage.py loaddata data.json
python manage.py runserver
The survey app needs some modes and employers defined in the database in order to work properly. The following steps will populate the appropriate database tables with some dummy default values.
psql -d checkin -c "INSERT INTO survey_mode VALUES (0, 'Biking', 6.8, 0, 11, TRUE);"
psql -d checkin -c "INSERT INTO survey_mode VALUES (1, 'Driving alone', 0, 518, 39.3, FALSE);"
psql -d checkin -c "INSERT INTO survey_employer VALUES (0, 'test employer 1', 1, FALSE, NULL, TRUE, FALSE);"
psql -d checkin -c "INSERT INTO survey_employer VALUES (1, 'test employer 2', 1, FALSE, NULL, TRUE, TRUE);"
psql -d checkin -c "INSERT INTO survey_month VALUES (0, '2019-02-01', '2010-01-01', '2019-01-29');"
su root
apt-get install postgresql postgis postgresql-client postgresql-server-dev python-dev virtualenvwrapper python-pip bash-completion
su postgres
createuser django
createdb -O django checkin
psql -d checkin -c "ALTER USER django WITH PASSWORD 'django';"
psql -d checkin -c "CREATE EXTENSION postgis;"
exit
Become a normal user: su <username>
(replace <username>
with your normal development user)
adduser guest
git clone <URL of this repository>
cd <this repository>
source /etc/bash_completion
mkvirtualenv greenstreets
Setup the environment variables in the postactivate script:
echo >>~/.virtualenvs/greenstreets/bin/postactivate <<EOF
export SECRET_KEY="abcdef"
export DB_NAME="checkin"
export DB_USER="django"
export DB_PASSWORD="django"
export DB_PORT="5432"
export DB_HOST="localhost"
export EMAIL_HOST_USER="xten"
export EMAIL_HOST_PASSWORD="xten"
export MANDRILL_API_KEY=""
export MAPQUEST_API_KEY=""
EOF
workon greenstreets
pip install -r requirements.txt
python manage.py migrate
python manage.py loaddata data.json
python manage.py runserver 0.0.0.0:8000
The survey app needs some modes and employers defined in the database in order to work properly. The following steps will populate the appropriate database tables with some dummy default values.
su postgres
psql -d checkin -c "INSERT INTO survey_mode VALUES (0, 'Biking', 6.8, 0, 11, TRUE);"
psql -d checkin -c "INSERT INTO survey_mode VALUES (1, 'Driving alone', 0, 518, 39.3, FALSE);"
psql -d checkin -c "INSERT INTO survey_employer VALUES (0, 'test employer 1', 1, FALSE, NULL, TRUE, FALSE);"
psql -d checkin -c "INSERT INTO survey_employer VALUES (1, 'test employer 2', 1, FALSE, NULL, TRUE, TRUE);"
psql -d checkin -c "INSERT INTO survey_month VALUES (0, '2019-02-01', '2010-01-01', '2019-01-29');"
exit
The admin interface is useful for easily editing the database. First, set up an admin user:
python manage.py createsuperuser
then just navigate to /admin
and login.
pip install -r requirements.txt
pip install -r test-requirements.txt
python manage.py test --settings=checkin2015.dev
psql -d checkin -c "\copy (select checkins.*, legs.* from (select a.id, a.name, a.email, orgs.employer_name, orgs.team_name, a.share, a.home_address, a.work_address, a.comments, a.carbon_change, a.carbon_savings, a.calorie_change, a.calories_total, a.change_type, a.already_green from survey_commutersurvey a left outer join (select m.id as employer_id, m.name as employer_name, n.id as team_id, n.name as team_name from survey_employer m left outer join survey_team n on m.id = n.parent_id) orgs on (a.employer_id = orgs.employer_id and a.team_id = orgs.team_id)) checkins right outer join (select x.checkin_id, x.day, x.direction, y.name, x.duration from survey_leg x, survey_mode y where x.mode_id = y.id) legs on checkins.id = legs.checkin_id) to ../Checkins.csv CSV HEADER"