- Install Git. You can do this by installing XCode Command Line tools.
- Install brew.
brew install python
. This also installs pip.pip install virtualenv
pip install virtualenvwrapper
brew install postgres
. IMPORTANT: Read what brew tells you. You might want to make start postgresql at loginln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
and then load postgresql now withlaunchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
.brew install postgis
- Check for errors with
brew doctor
if desired.
git clone https://github.com/greenstreetsinitiative/checkin2015.git
OR fork (via the Github website) and clone your fork.- Navigate to the checkin2015 directory in your terminal.
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.- Find .virtualenvs/greenstreets/bin/postactivate and edit that file to include the environment variables:
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
- If you have data...
- then run:
python manage.py loaddata data.json
- else, see the next section Populate the database with dummy data
- then run:
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');"
- Note: The above command sets Walk/Ride Day to some time way in the future, but activates the checkin now. Just don't be surprised when you see "this month" and "2019" in the same sentence.
- Become root:
su root
apt-get install postgresql postgis postgresql-client postgresql-server-dev python-dev virtualenvwrapper python-pip bash-completion
- Become postgres:
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)- If you don't have a normal user in your VM yet, make one first:
adduser guest
- If you don't have a normal user in your VM yet, make one first:
-
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
- If you have data...
- then run:
python manage.py loaddata data.json
- else, see the next section Populate the database with dummy data
- then run:
python manage.py runserver 0.0.0.0:8000
- Navigate to the IP address of your debian VM in your web browser, port 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.
- Become postgres:
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');"
- Note: The above command sets Walk/Ride Day to some time way in the future, but activates the checkin now. Just don't be surprised when you see "this month" and "2019" in the same sentence.
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"
- Complete "Setting Up Your Machine" at https://developers.openshift.com/managing-your-applications/client-tools.html
- https://www.openshift.com/
- Click My Account -> OpenShift Web Console
- Log-in with the username and password
- Click checkindev under applications
- Copy the Source Code on the right side
- Clone the repository (e.g. "git clone ssh://57b...")
- Change directories to the cloned repo.
- Connect a new repo via an upstream (e.g. "git remote add upstream -m master git://github.com/openshift/django-example.git")
- Pull the upstream repo (e.g. "git pull -s recursive -X theirs upstream master")
- Run "git push" to finish the update