Django app for the monitoring and management of Vespa velutina, an invasive species in Belgium.
- Create an empty PostgreSQL database (e.g.
vespa-watch
) - Enable PostGIS:
CREATE EXTENSION postgis;
- Clone this repository:
git clone https://github.com/inbo/vespa-watch
- Copy
djangoproject/settings/settings_local.template.py
todjangoproject/settings/settings_local.py
- In that file, verify the database settings are correct and set
SECRET_KEY
to a non-empty value
- Create a virtual environment, e.g.
conda create -n vespawatch python=3.6
- Activate the environment, e.g.
source activate vespawatch
- Navigate to the project directory and install the requirements:
pip install -r requirements.txt
- Tell Django to use the local settings:
export DJANGO_SETTINGS_MODULE=djangoproject.settings.settings_local
Make sure you have npm installed. You'll need to run an npm script to build all static files.
python manage.py migrate
-
In development (this will prompt for a username, email and password):
python manage.py createsuperuser
-
In production:
python manage.py create_su
-
Fire brigade users are responsible for a specific geographic area (= zone). Import the polygons for those zones:
python manage.py import_firefighters_zones data/Brandweerzones_2019.geojson
File source
The initial fire brigade zone data was received as an ESRI shapefile and converted to GeoJSON with:
ogr2ogr -f GeoJSON -t_srs EPSG:4326 data/Brandweerzones_2019.geojson <path_to_received_shapefile>/Brandweerzones_2019.shp
-
Create a fire brigade user for each zone (this will return passwords for each account, so best to catch those):
python manage.py create_firefighters_accounts
Initialize the database with observations from iNaturalist (optional):
python manage.py sync_pull
The repository contains a number of raw static files that need to be processed before deployment. You can build all static files with an npm script:
npm run build:all
In your virtual environment:
python manage.py runserver
Go to http://localhost:8000 to see the application.
HTML is defined in templates at vespawatch/templates/vespawatch
. base.html
is the main template, almost all other templates build upon it. The HTML is structured around Bootstrap v4.0 classes for layout, components and utilities: use these before writing custom html and css.
Important: static files in the Django accessible directory vespawatch/static/vespawatch
should not be edited manually: those are all generated! They are managed in static_src
and copied or compiled with Node Package Manager using npm run build:all
. To start:
- Verify npm is installed:
node -v
- Go to the root of this repository
- Install all dependencies with:
npm install
(will readpackage.json
to create thenode_modules
directory)
CSS is managed as SCSS, starting from Bootstrap's SCSS, with custom variable overwrites in _variables.scss
and custom CSS in main.scss
. These get bundled together with Bootstrap in a single vespawatch/static/vespawatch/css/main.css
.
- Go to
static_src/scss
- Update the relevant
.scss
files - Generate the CSS automatically on every change with
npm run watch:css
(or once withnpm run create:css
).
External Javascript libraries (and their CSS) are defined in package.json
. To add a library:
- Add the library and version in
package.json
underdependencies
- Install the library with
npm install
- Create a new script in
package.json
underscripts
to move the necessary JS & CSS files tovespawatch/static/vespawatch/libraries
(see the other scripts for inspiration) and add your script tocopy:libraries
- Move the files with
npm run copy:libraries
- Link to the files in your template with:
<link rel="stylesheet" href="{% static 'vespawatch/libraries/my_library/my_library.min.css' %}"> <script src="{% static 'vespawatch/libraries/my_library/my_library.min.js' %}"></script>
- Go to
static_src/js
- Update the relevant
.js
files - Copy the files automatically on every changes with
npm run watch:js
(or once withnpm run copy:custom-js
)
- Go to
static_src/img
- Add or update the relevant image files
- Copy the files with
npm run copy:img
-
Extract the translations from the code to .po files
$ python manage.py makemessages -l nl $ python manage.py makemessages -d djangojs -l nl
-
Complete the translations in
locale/nl/LC_MESSAGES/django.po
andlocale/nl/LC_MESSAGES/djangojs.po
. A simple text editor is enough, but more advanced tools such as Qt Linguist can more convenient. -
Compile .po => .mo
$ python manage.py compilemessages
-
Rince and repeat.