From 69c623e71c0d196858bb3b0a5e690390c0ac2033 Mon Sep 17 00:00:00 2001 From: tokumaru Date: Sat, 29 Sep 2018 15:47:20 -0700 Subject: [PATCH 01/14] Move CONTRIBUTING.md to docs/. --- CONTRIBUTING.md => docs/CONTRIBUTING.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CONTRIBUTING.md => docs/CONTRIBUTING.md (100%) diff --git a/CONTRIBUTING.md b/docs/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to docs/CONTRIBUTING.md From f04a1a2f31b9c35d7fc7e6a10150407f5c69cd33 Mon Sep 17 00:00:00 2001 From: tokumaru Date: Sat, 29 Sep 2018 15:49:29 -0700 Subject: [PATCH 02/14] Minor context comments on hidden files. --- .autopep8.py | 7 +++++-- .gitignore | 2 ++ .pylint.py | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.autopep8.py b/.autopep8.py index 70199b7..e8bbd88 100755 --- a/.autopep8.py +++ b/.autopep8.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# TODO: Explain usage here? Why do we need both pylint and pep8? import os import subprocess @@ -10,7 +11,9 @@ if path.startswith(current_path + '/project/'): path = path.replace(current_path + '/project/', '/src/') subprocess.run(['docker-compose', 'exec', '-T', 'web', 'sh', '-c', - "PYTHONPATH=/src/extrasrc autopep8 {} {}".format(" ".join(sys.argv[1:-1]), path)], + "PYTHONPATH=/src/extrasrc autopep8 {} {}".format(" ".join( + sys.argv[1:-1]), path)], stdout=sys.stdout) else: - subprocess.run([os.environ['HOME'] + '/.local/bin/autopep8'] + sys.argv[1:]) + subprocess.run( + [os.environ['HOME'] + '/.local/bin/autopep8'] + sys.argv[1:]) diff --git a/.gitignore b/.gitignore index 2c34aab..8294010 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# Define what we choose not to track on git. + ### Django ### *.log *.pot diff --git a/.pylint.py b/.pylint.py index d33b2e5..eb56a94 100755 --- a/.pylint.py +++ b/.pylint.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# TODO: Explain usage here? Why do we need both pylint and pep8? import os import subprocess @@ -10,7 +11,8 @@ if path.startswith(current_path + '/project/'): path = path.replace(current_path + '/project/', '/src/') subprocess.run(['docker-compose', 'exec', '-T', 'web', 'sh', '-c', - "PYTHONPATH=/src/extrasrc pylint {} {}".format(" ".join(sys.argv[1:-1]), path)], + "PYTHONPATH=/src/extrasrc pylint {} {}".format(" ".join( + sys.argv[1:-1]), path)], stdout=sys.stdout) else: subprocess.run([os.environ['HOME'] + '/.local/bin/pylint'] + sys.argv[1:]) From 0a95b22c1abb2b019918ccc8ae949a4736346839 Mon Sep 17 00:00:00 2001 From: tokumaru Date: Sat, 29 Sep 2018 15:51:09 -0700 Subject: [PATCH 03/14] Fix links for contributing at bottom of README. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c5b4bdc..5ae6404 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,4 @@ make run ``` ## Contributing -Please refer to the [developer guide](./docs/DEVELOPER.md) and [contribution guide](./CONTRIBUTING.md) to learn how the backend is structured. +Please refer to the [developer guide](./docs/DEVELOPER.md) and [contribution guide](./docs/CONTRIBUTING.md) to learn how the backend is structured. From a3c77b29a58b5f4891dde7c96206fb0cee5ef6ff Mon Sep 17 00:00:00 2001 From: tokumaru Date: Sat, 29 Sep 2018 16:00:03 -0700 Subject: [PATCH 04/14] Add brief summary of codebase layout to README. --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 5ae6404..738c78d 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,16 @@ make run ## Contributing Please refer to the [developer guide](./docs/DEVELOPER.md) and [contribution guide](./docs/CONTRIBUTING.md) to learn how the backend is structured. + +## Architecture +config: Configuration files and requirements. + +docs: Documentation and example database. + +project/api/migrations: Auto-generated migration classes? + +project/api: REST API and a test file (how/why do we run the test)? Defines the Nation, Territory, and DiplomaticRelation classes, which are our primary database items. + +project/interactivemap: Django settings and website directory layout? + +project: Django execution wrapper. From 59afcbbc32bd758978df6fd752baac690e631cfe Mon Sep 17 00:00:00 2001 From: tokumaru Date: Sat, 6 Oct 2018 19:50:25 -0700 Subject: [PATCH 05/14] Move Local Development instructions to README and embellish them. --- README.md | 35 +++++++++++++++++++++++++++++++++++ docs/DEVELOPER.md | 11 ----------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 738c78d..4e83fcf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # ChronoScio Backend [![Build Status](https://travis-ci.org/chronoscio/backend.svg?branch=master)](https://travis-ci.org/interactivemap/backend) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0074e97bc13b476ea3eec279483d3cab)](https://www.codacy.com/app/whirish/backend?utm_source=github.com&utm_medium=referral&utm_content=interactivemap/backend&utm_campaign=Badge_Grade) ## Getting Started +We normally use [Docker](https://en.wikipedia.org/wiki/Docker_(software)) to simplify installation and configuration. Docker makes virtual "containers" as images which allow us to isolate code we run and work around computer-specific weirdnesses. Docker should work on [Linux](https://docs.docker.com/install/linux/docker-ce/ubuntu/) or [macOS](https://docs.docker.com/docker-for-mac/install/) but requires Hyper-V, which is not available on Windows 10 Home edition. If you have trouble with setting up Docker, see the **Local Development** instructions below instead. Otherwise, it should be simple to get started: ```bash # Clone the repo git clone https://github.com/chronoscio/backend @@ -16,6 +17,40 @@ make run # try again in a few seconds ``` +## Local Development +1) Create a python virtualenv, activate it, and install the package requirements: +```bash +# Clone the repo if you have not already. +git clone https://github.com/chronoscio/backend + +# Navigate to the backend repo. +cd backend + +# Begin a virtual environmnet. +virtualenv venv + +# Activate the virtual environment. +source venv/bin/activate + +# Install the project requirements manually. +pip install -r config/requirements.txt +``` +2) Install and run [Postgresql](https://www.postgresql.org/docs/9.3/static/tutorial-install.html) (AKA postgres) locally. You should not need to worry about creating any accounts or doing any setup but you may need to debug OS-specific problems that appear. For example, you may need to install postgis as well. (TODO: Test this on wiped setups to find out specific steps to do this properly.) +3) Change the HOST variable in the [settings.py](https://github.com/chronoscio/backend/blob/master/project/interactivemap/settings.py) file to be `localhost` instead of `db`. You may also need to change the PORT variable to match whatever you have set for postgis (TODO: investigate this). +4) Prepare a json dataset fto be the database. For now, you can use our example test data. +```bash +mv docs/example_db_dump.json project/db.json +``` + +5) Migrate and run the server with django. +```bash +# Migrate the project. +python project/manage.py migrate + +# Run the server. +python3 project/manage.py runserver +``` + ## Contributing Please refer to the [developer guide](./docs/DEVELOPER.md) and [contribution guide](./docs/CONTRIBUTING.md) to learn how the backend is structured. diff --git a/docs/DEVELOPER.md b/docs/DEVELOPER.md index d205bda..041fbf0 100644 --- a/docs/DEVELOPER.md +++ b/docs/DEVELOPER.md @@ -47,17 +47,6 @@ principally interacted with via a `Makefile`. Running `make` or `make help` will a documented list of all available commands and shortcuts to help with development, so a nuanced understanding of docker is not necessary for code contribution. -## Local Development - -If you are having trouble with Docker (e.g. on Windows), this project can also be run locally with -the following changes: - -- Create a python virtualenv, activate it, and install the package requirements: - `cd backend; virtualenv venv; source venv/bin/activate; pip install -r config/requirements.txt` -- Install and run Postgres locally -- Change your DATABASES > default > HOST variable to `localhost` (and maybe change the port to - match your Postgres database) - ## API endpoints ```bash From 70650eb217395e1eb01bc0a34d04cda4d7a5e03c Mon Sep 17 00:00:00 2001 From: tokumaru Date: Sat, 6 Oct 2018 20:02:50 -0700 Subject: [PATCH 06/14] Add more detail about Local Development. --- README.md | 15 +++++++++++++-- docs/DEVELOPER.md | 8 +++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4e83fcf..0712201 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,17 @@ python project/manage.py migrate # Run the server. python3 project/manage.py runserver ``` +You should see a terminal output similar to this: +``` +Performing system checks... -## Contributing -Please refer to the [developer guide](./docs/DEVELOPER.md) and [contribution guide](./docs/CONTRIBUTING.md) to learn how the backend is structured. +System check identified no issues (0 silenced). +January 01, 2018 - 00:00:00 +Django version 2.0.7, using settings 'interactivemap.settings' +Starting development server at http://127.0.0.1:8000/ +Quit the server with CONTROL-C. +``` +Then go to `http://localhost:8000/admin/` to see the Django administration panel. You should now be able to add Nations or Territories to the API and should see an Auth token after setting up your authetication (see developer guide). Try making an arbitrary Nation and then a Territory for that nation. Be sure to use the polygon outline tool when drawing on the Territory mapper. You will need to zoom out to see the world map properly as it starts fully zoomed in above the Atlantic Ocean (0, 0 coordinates). ## Architecture config: Configuration files and requirements. @@ -66,3 +74,6 @@ project/api: REST API and a test file (how/why do we run the test)? Defines the project/interactivemap: Django settings and website directory layout? project: Django execution wrapper. + +## Contributing +Please refer to the [developer guide](./docs/DEVELOPER.md) and [contribution guide](./docs/CONTRIBUTING.md) to learn more about how we structure the backend. We try to centralize most important discussion in PRs and Issues. diff --git a/docs/DEVELOPER.md b/docs/DEVELOPER.md index 041fbf0..0e28697 100644 --- a/docs/DEVELOPER.md +++ b/docs/DEVELOPER.md @@ -29,9 +29,11 @@ which provides us with a stateless JWT which can be validated through their serv [access token](https://auth0.com/docs/tokens/access-token) is required to be passed to the backend. You can run tests locally with your own Auth0 configuration as follows: -1. Log into https://manage.auth0.com/#/applications -2. Create Application > All Scopes > Authorize -3. See the `client_id`, `client_secret`, and `audience` variables in the example cURL +1. Log into https://manage.auth0.com/#/applications. It does not matter what names you select. +2. Create Application > All Scopes > Authorize. Or just create a SPA (Single Page Application). +3. See the `client_id`, `client_secret`, and `audience` variables in the example cURL. + +You should not have to do anything with this information, just make sure that it exists. ### Database From 3e0d9a0bd7ead5513fc1017e1f839bfd7c83ebb5 Mon Sep 17 00:00:00 2001 From: tokumaru Date: Sat, 6 Oct 2018 20:39:25 -0700 Subject: [PATCH 07/14] Clarify Auth0 usage when hosting locally. --- README.md | 19 ++++++++++++++----- django.env.sample | 9 +++++---- project/interactivemap/settings.py | 6 +++--- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0712201..284ad43 100644 --- a/README.md +++ b/README.md @@ -34,15 +34,24 @@ source venv/bin/activate # Install the project requirements manually. pip install -r config/requirements.txt + +# Create env files and note that you will need to modify them later. +mv django.env.sample django.env +mv postgres.env.sample postgres.env ``` -2) Install and run [Postgresql](https://www.postgresql.org/docs/9.3/static/tutorial-install.html) (AKA postgres) locally. You should not need to worry about creating any accounts or doing any setup but you may need to debug OS-specific problems that appear. For example, you may need to install postgis as well. (TODO: Test this on wiped setups to find out specific steps to do this properly.) -3) Change the HOST variable in the [settings.py](https://github.com/chronoscio/backend/blob/master/project/interactivemap/settings.py) file to be `localhost` instead of `db`. You may also need to change the PORT variable to match whatever you have set for postgis (TODO: investigate this). -4) Prepare a json dataset fto be the database. For now, you can use our example test data. +2) Create an SPA (Single Page Application) at https://manage.auth0.com/#/applications. +3) Go to the Settings of your SPA put your Client ID and Client Secret into `django.env`. +``` +AUTH0_CLIENT_ID={Client ID} +AUTH0_CLIENT_SECRET={Client Secret} +``` +4) Install and run [Postgresql](https://www.postgresql.org/docs/9.3/static/tutorial-install.html) (AKA postgres) locally. You should not need to worry about creating any accounts or doing any setup but you may need to debug OS-specific problems that appear. For example, you may need to install postgis as well. (TODO: Test this on wiped setups to find out specific steps to do this properly.) +5) Change the HOST variable in the [settings.py](https://github.com/chronoscio/backend/blob/master/project/interactivemap/settings.py) file to be `localhost` instead of `db`. You may also need to change the PORT variable to match whatever you have set for postgis (TODO: investigate this). +6) Prepare a json dataset to be the database. For now, you can use our example test data. ```bash mv docs/example_db_dump.json project/db.json ``` - -5) Migrate and run the server with django. +7) Migrate and run the server with django. ```bash # Migrate the project. python project/manage.py migrate diff --git a/django.env.sample b/django.env.sample index 1e06668..dda437b 100644 --- a/django.env.sample +++ b/django.env.sample @@ -4,7 +4,8 @@ ADMIN_USER=admin ADMIN_EMAIL=admin@example.com ADMIN_PASS=p@55w0rd1 -AUTH0_DOMAIN={DOMAIN} -AUTH0_CLIENT_ID={ID} -AUTH0_CLIENT_SECRET={SECRET} -API_IDENTIFIER={IDENTIFIER} +AUTH0_DOMAIN=chronoscio.auth0.com +API_IDENTIFIER=https://chronoscio.org/api/ + +AUTH0_CLIENT_ID={Client ID} +AUTH0_CLIENT_SECRET={Client Secret} diff --git a/project/interactivemap/settings.py b/project/interactivemap/settings.py index 195cd6a..6ea0a3f 100644 --- a/project/interactivemap/settings.py +++ b/project/interactivemap/settings.py @@ -167,10 +167,10 @@ 'interactivemap-frontend-*.now.sh', ) -AUTH0_DOMAIN = os.environ.get('AUTH0_DOMAIN', 'chronoscio.auth0.com') +AUTH0_DOMAIN = os.environ.get('AUTH0_DOMAIN') API_IDENTIFIER = os.environ.get('API_IDENTIFIER', 'https://chronoscio.org/') -AUTH0_CLIENT_ID = os.environ.get('AUTH0_CLIENT_ID', '') -AUTH0_CLIENT_SECRET = os.environ.get('AUTH0_CLIENT_SECRET', '') +AUTH0_CLIENT_ID = os.environ.get('AUTH0_CLIENT_ID') +AUTH0_CLIENT_SECRET = os.environ.get('AUTH0_CLIENT_SECRET') PUBLIC_KEY = None JWT_ISSUER = None From be78185de4ea2a99aa7fe6937299a7a942daaff8 Mon Sep 17 00:00:00 2001 From: tokumaru Date: Sat, 6 Oct 2018 20:46:24 -0700 Subject: [PATCH 08/14] Revise lint/format meta comments. --- .autopep8.py | 3 ++- .pylint.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.autopep8.py b/.autopep8.py index e8bbd88..5cc8091 100755 --- a/.autopep8.py +++ b/.autopep8.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 -# TODO: Explain usage here? Why do we need both pylint and pep8? +# Autopep8 is a tool to automatically format python code according to the PEP8 +# standards. Github uses this file for Continuous Integration. import os import subprocess diff --git a/.pylint.py b/.pylint.py index eb56a94..321715b 100755 --- a/.pylint.py +++ b/.pylint.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 -# TODO: Explain usage here? Why do we need both pylint and pep8? +# Pylint is a tool to lint (style) python code. +# Github uses this file for Continuous Integration. import os import subprocess From 86985af71893ed054eb1ce6f0e59dd4612ffa68e Mon Sep 17 00:00:00 2001 From: tokumaru Date: Sat, 6 Oct 2018 20:49:58 -0700 Subject: [PATCH 09/14] Request user to set auth0 domain too. --- README.md | 3 ++- django.env.sample | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 284ad43..6a9f765 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,9 @@ mv django.env.sample django.env mv postgres.env.sample postgres.env ``` 2) Create an SPA (Single Page Application) at https://manage.auth0.com/#/applications. -3) Go to the Settings of your SPA put your Client ID and Client Secret into `django.env`. +3) Go to the Settings of your SPA put your Client ID and Client Secret into `django.env` along with the website domain. ``` +AUTH0_DOMAIN={PROJECT.auth0.com} AUTH0_CLIENT_ID={Client ID} AUTH0_CLIENT_SECRET={Client Secret} ``` diff --git a/django.env.sample b/django.env.sample index dda437b..d7c7b43 100644 --- a/django.env.sample +++ b/django.env.sample @@ -3,9 +3,8 @@ SECRET=dummy ADMIN_USER=admin ADMIN_EMAIL=admin@example.com ADMIN_PASS=p@55w0rd1 - -AUTH0_DOMAIN=chronoscio.auth0.com API_IDENTIFIER=https://chronoscio.org/api/ +AUTH0_DOMAIN={PROJECT.auth0.com} AUTH0_CLIENT_ID={Client ID} AUTH0_CLIENT_SECRET={Client Secret} From 6894f5f370ac07ae8d85ea25957c5c57e5f1082f Mon Sep 17 00:00:00 2001 From: tokumaru Date: Sat, 6 Oct 2018 21:27:13 -0700 Subject: [PATCH 10/14] Modify clarifications to be a bit less wordy. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6a9f765..6bec4d3 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ AUTH0_DOMAIN={PROJECT.auth0.com} AUTH0_CLIENT_ID={Client ID} AUTH0_CLIENT_SECRET={Client Secret} ``` -4) Install and run [Postgresql](https://www.postgresql.org/docs/9.3/static/tutorial-install.html) (AKA postgres) locally. You should not need to worry about creating any accounts or doing any setup but you may need to debug OS-specific problems that appear. For example, you may need to install postgis as well. (TODO: Test this on wiped setups to find out specific steps to do this properly.) +4) Install and run [Postgresql](https://www.postgresql.org/docs/9.3/static/tutorial-install.html) (AKA postgres) locally. You should not need to worry about creating any accounts. You will also need to make sure you have set up [geodjango](https://docs.djangoproject.com/en/2.1/ref/contrib/gis/install/). (TODO: Test this on wiped setups to find out specific steps to do this properly.) 5) Change the HOST variable in the [settings.py](https://github.com/chronoscio/backend/blob/master/project/interactivemap/settings.py) file to be `localhost` instead of `db`. You may also need to change the PORT variable to match whatever you have set for postgis (TODO: investigate this). 6) Prepare a json dataset to be the database. For now, you can use our example test data. ```bash @@ -54,7 +54,7 @@ mv docs/example_db_dump.json project/db.json ``` 7) Migrate and run the server with django. ```bash -# Migrate the project. +# Run SQL migrations. python project/manage.py migrate # Run the server. @@ -81,9 +81,9 @@ project/api/migrations: Auto-generated migration classes? project/api: REST API and a test file (how/why do we run the test)? Defines the Nation, Territory, and DiplomaticRelation classes, which are our primary database items. -project/interactivemap: Django settings and website directory layout? +project/interactivemap: Standard Django settings and website directory layout. -project: Django execution wrapper. +project: Standard Django aplication directory ## Contributing Please refer to the [developer guide](./docs/DEVELOPER.md) and [contribution guide](./docs/CONTRIBUTING.md) to learn more about how we structure the backend. We try to centralize most important discussion in PRs and Issues. From b45f548e8e826f0bb6e5c8b7018a82c29dd25a93 Mon Sep 17 00:00:00 2001 From: tokumaru Date: Mon, 8 Oct 2018 13:13:01 -0700 Subject: [PATCH 11/14] Tentatively put bash for quality standards though the file is not necessarily an sh file. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6bec4d3..3717e72 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ mv postgres.env.sample postgres.env ``` 2) Create an SPA (Single Page Application) at https://manage.auth0.com/#/applications. 3) Go to the Settings of your SPA put your Client ID and Client Secret into `django.env` along with the website domain. -``` +```bash AUTH0_DOMAIN={PROJECT.auth0.com} AUTH0_CLIENT_ID={Client ID} AUTH0_CLIENT_SECRET={Client Secret} From 4068a05a2b927146eb88a9e111b51f1c9f44f433 Mon Sep 17 00:00:00 2001 From: tokumaru Date: Mon, 8 Oct 2018 13:25:38 -0700 Subject: [PATCH 12/14] Update url, .travis.yml, and other tweaks reqested in review. --- README.md | 17 ++++++++++++----- django.env.sample | 8 ++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3717e72..3dc7a75 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ make run # Navigate to http://localhost/, if you get a 502 error postgres likely has not been initialized yet, # try again in a few seconds ``` +Use `docker-compose down` to stop hosting when you are done. ## Local Development 1) Create a python virtualenv, activate it, and install the package requirements: @@ -39,29 +40,35 @@ pip install -r config/requirements.txt mv django.env.sample django.env mv postgres.env.sample postgres.env ``` -2) Create an SPA (Single Page Application) at https://manage.auth0.com/#/applications. +2) Create an SPA (Single Page Application) [here](https://manage.auth0.com/#/applications). 3) Go to the Settings of your SPA put your Client ID and Client Secret into `django.env` along with the website domain. ```bash +API_IDENTIFIER={IDENTIFIER} AUTH0_DOMAIN={PROJECT.auth0.com} AUTH0_CLIENT_ID={Client ID} AUTH0_CLIENT_SECRET={Client Secret} ``` -4) Install and run [Postgresql](https://www.postgresql.org/docs/9.3/static/tutorial-install.html) (AKA postgres) locally. You should not need to worry about creating any accounts. You will also need to make sure you have set up [geodjango](https://docs.djangoproject.com/en/2.1/ref/contrib/gis/install/). (TODO: Test this on wiped setups to find out specific steps to do this properly.) +4) Install and run [Postgresql](https://www.postgresql.org/docs/9.3/static/tutorial-install.html) (AKA postgres) locally. You should not need to worry about creating any accounts. You will also need to make sure you have set up [geodjango](https://docs.djangoproject.com/en/stable/contrib/gis/install/). (TODO: Test this on wiped setups to find out specific steps to do this properly.) 5) Change the HOST variable in the [settings.py](https://github.com/chronoscio/backend/blob/master/project/interactivemap/settings.py) file to be `localhost` instead of `db`. You may also need to change the PORT variable to match whatever you have set for postgis (TODO: investigate this). 6) Prepare a json dataset to be the database. For now, you can use our example test data. ```bash -mv docs/example_db_dump.json project/db.json +cp docs/example_db_dump.json project/db.json ``` +If this is the first time you are using django, you must also create a user account to log in with. +```bash +python project/manage.py createsuperuser +``` +Then follow the prompts to set a username, email, and password you will use when you navigate to `http://localhost:8000/admin/` later. 7) Migrate and run the server with django. ```bash # Run SQL migrations. python project/manage.py migrate # Run the server. -python3 project/manage.py runserver +python project/manage.py runserver ``` You should see a terminal output similar to this: -``` +```bash Performing system checks... System check identified no issues (0 silenced). diff --git a/django.env.sample b/django.env.sample index d7c7b43..1e06668 100644 --- a/django.env.sample +++ b/django.env.sample @@ -3,8 +3,8 @@ SECRET=dummy ADMIN_USER=admin ADMIN_EMAIL=admin@example.com ADMIN_PASS=p@55w0rd1 -API_IDENTIFIER=https://chronoscio.org/api/ -AUTH0_DOMAIN={PROJECT.auth0.com} -AUTH0_CLIENT_ID={Client ID} -AUTH0_CLIENT_SECRET={Client Secret} +AUTH0_DOMAIN={DOMAIN} +AUTH0_CLIENT_ID={ID} +AUTH0_CLIENT_SECRET={SECRET} +API_IDENTIFIER={IDENTIFIER} From 3a3ee8d3d49a817671613c7615c7033b09b3dd9e Mon Sep 17 00:00:00 2001 From: tokumaru Date: Sat, 13 Oct 2018 16:14:43 -0700 Subject: [PATCH 13/14] Undo changes to settings.py for now for CI. --- project/interactivemap/settings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/project/interactivemap/settings.py b/project/interactivemap/settings.py index 6ea0a3f..195cd6a 100644 --- a/project/interactivemap/settings.py +++ b/project/interactivemap/settings.py @@ -167,10 +167,10 @@ 'interactivemap-frontend-*.now.sh', ) -AUTH0_DOMAIN = os.environ.get('AUTH0_DOMAIN') +AUTH0_DOMAIN = os.environ.get('AUTH0_DOMAIN', 'chronoscio.auth0.com') API_IDENTIFIER = os.environ.get('API_IDENTIFIER', 'https://chronoscio.org/') -AUTH0_CLIENT_ID = os.environ.get('AUTH0_CLIENT_ID') -AUTH0_CLIENT_SECRET = os.environ.get('AUTH0_CLIENT_SECRET') +AUTH0_CLIENT_ID = os.environ.get('AUTH0_CLIENT_ID', '') +AUTH0_CLIENT_SECRET = os.environ.get('AUTH0_CLIENT_SECRET', '') PUBLIC_KEY = None JWT_ISSUER = None From a76de9b2105ba39752c104440893e1b5a5b9bbad Mon Sep 17 00:00:00 2001 From: tokumaru Date: Sat, 13 Oct 2018 16:22:29 -0700 Subject: [PATCH 14/14] Update README for undoing changes to .travis.yml and settings.py. --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3dc7a75..695fb24 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # ChronoScio Backend [![Build Status](https://travis-ci.org/chronoscio/backend.svg?branch=master)](https://travis-ci.org/interactivemap/backend) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0074e97bc13b476ea3eec279483d3cab)](https://www.codacy.com/app/whirish/backend?utm_source=github.com&utm_medium=referral&utm_content=interactivemap/backend&utm_campaign=Badge_Grade) ## Getting Started -We normally use [Docker](https://en.wikipedia.org/wiki/Docker_(software)) to simplify installation and configuration. Docker makes virtual "containers" as images which allow us to isolate code we run and work around computer-specific weirdnesses. Docker should work on [Linux](https://docs.docker.com/install/linux/docker-ce/ubuntu/) or [macOS](https://docs.docker.com/docker-for-mac/install/) but requires Hyper-V, which is not available on Windows 10 Home edition. If you have trouble with setting up Docker, see the **Local Development** instructions below instead. Otherwise, it should be simple to get started: +We normally use [Docker](https://en.wikipedia.org/wiki/Docker_(software)) to simplify installation and configuration. Docker makes virtual "containers" as images which allow us to isolate code we run and work around computer-specific weirdnesses. Docker should work on [Linux](https://docs.docker.com/install/linux/docker-ce/ubuntu/) or [macOS](https://docs.docker.com/docker-for-mac/install/) but requires Hyper-V, which is not available on Windows 10 Home edition. It does works on Windows 10 Pro 64 bit. If you have trouble with setting up Docker, see the **Local Development** instructions below instead. Otherwise, it should be simple to get started: ```bash # Clone the repo git clone https://github.com/chronoscio/backend @@ -16,7 +16,7 @@ make run # Navigate to http://localhost/, if you get a 502 error postgres likely has not been initialized yet, # try again in a few seconds ``` -Use `docker-compose down` to stop hosting when you are done. +Use `make stop` or `make clean` to stop hosting when you are done. ## Local Development 1) Create a python virtualenv, activate it, and install the package requirements: @@ -44,12 +44,12 @@ mv postgres.env.sample postgres.env 3) Go to the Settings of your SPA put your Client ID and Client Secret into `django.env` along with the website domain. ```bash API_IDENTIFIER={IDENTIFIER} -AUTH0_DOMAIN={PROJECT.auth0.com} -AUTH0_CLIENT_ID={Client ID} -AUTH0_CLIENT_SECRET={Client Secret} +AUTH0_DOMAIN={DOMAIN} +AUTH0_CLIENT_ID={ID} +AUTH0_CLIENT_SECRET={Secret} ``` 4) Install and run [Postgresql](https://www.postgresql.org/docs/9.3/static/tutorial-install.html) (AKA postgres) locally. You should not need to worry about creating any accounts. You will also need to make sure you have set up [geodjango](https://docs.djangoproject.com/en/stable/contrib/gis/install/). (TODO: Test this on wiped setups to find out specific steps to do this properly.) -5) Change the HOST variable in the [settings.py](https://github.com/chronoscio/backend/blob/master/project/interactivemap/settings.py) file to be `localhost` instead of `db`. You may also need to change the PORT variable to match whatever you have set for postgis (TODO: investigate this). +5) Change the HOST variable in the [settings.py](https://github.com/chronoscio/backend/blob/master/project/interactivemap/settings.py) file to be `localhost` instead of `db` as you will be hosting locally. Set `AUTH0_DOMAIN` to `None` near the bottom of the file as well so that it is compatible with the other local hosting defaults. You may also need to change the PORT variable to match whatever you have set for postgis (TODO: investigate this). 6) Prepare a json dataset to be the database. For now, you can use our example test data. ```bash cp docs/example_db_dump.json project/db.json