This repo contains a django project implementing the django-ebagis application. Included is a Windows batch file to simplify setup/installation of this project and its dependencies on the Basins server.
The included batch file scripts the configuration process for this project. It is currently setup specifically for the Basins server, but I would like to rewrite it to not be system-specific.
The script assumes Anaconda has been installed to the system and that the GeoDjango dependencies have been installed correctly. The script also assumes the ArcGIS version installed is 10.3; other versions of ArcGIS will required modification of the script as some paths are currently hard-coded.
To begin setup, create a project directory with the desired name and location on disk. Within that directory, clone this repository. From the command line, navigate to the cloned directory. Next, run the setup.bat file with three arguments:
$ setup.bat <name_of_project> <postgres_username> <postgres_password>
The batch file will do the following:
-
Clone the django-ebagis repositry. The script will attempt to use a stored ssh key to access the repo with push access, but if that fails it will clone the repo read-only over https.
-
Create via conda a python environment for the project using the project name, installing the dependencies in
conda-requirements.txt
. -
Activate said environment.
-
Install django-ebagis via its
requirements.txt
. It will be installed in development mode, such that the cloned repo will be linked to the environment and changes to its files will effect the project. -
Install the dependencies in
requirements.txt
, including django-windows-tools. -
Create a database named with the specified project name in the local postgres installation, using the template
postgis_21
and tablespacegis_data
. The user and password for authentication will be those provided to the script as arguments.
NOTE: the password does not currently get passed to the command, so the user must input it again, manually. -
Create the
secret.py
file required by the settings module, containing the project's secret key and the database name, user, and password.
NOTE: this file is not tracked by git and should never be added as it contains highly sensitive information. -
Create a .pth file pointing to arcpy in the environment's site-packages folder.
-
Run the
python manage.py migrate
command to setup the database to hold the project's models.
As both this project and the installed django-ebagis are git repositories,
most updates should be easily installed simply by running the git pull
command in the root of the repository with updates.
The necessary commands to set this up should be mostly automated through django-windows-tools. From the docs:
-
First, cd into the project root directory. Also, ensure the correct conda environment is active. If not, use
activate <env_name>
to activate it. -
Begin by collecting all static assets using the standard django manage.py command:
$ python manage.py collectstatic
-
Within the
static
directory this command will create, make a file calledweb.config
with the following:<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <!-- this configuration overrides the FastCGI handler to let IIS serve the static files --> <handlers> <clear/> <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" /> </handlers> </system.webServer> </configuration>
-
Setup the IIS site with the following command:
$ python manage.py winfcgi_install --site-name <project_name> --monitor-changes-to <full_path_to_touch_this_to_update_cgi.txt> --binding=https://*:443
A development instance simply requires use of the django development server and celery. These can easily be started in separate command prompt windows:
-
First, cd into the project root directory in each window. Also, ensure the correct conda environment is active. If not, use
activate <env_name>
to activate it. -
In one window, run the command
python manage.py runserver
. This should start the development web server accessible at the localhost on port 8000.
NOTE: do not use this server for connections across a network. It is not secure. -
In the other window, run the command
celery -A ebagis_site worker -l info
. Celery should start running and will then be available for tasks.
Better automation of this process is planned but not a priority.