Django app for the monitoring and management of Vespa velutina, an invasive species in Belgium.
Note: deployment instructions of application are provided in deployment dir
- 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.pytodjangoproject/settings/settings_local.py - In that file, verify the database settings are correct and set
SECRET_KEYto 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
Initialize the database with observations from iNaturalist (optional):
python manage.py sync_pullThe 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 install # first time only
$ npm run build:allIn your virtual environment:
$ export DJANGO_SETTINGS_MODULE=djangoproject.settings.settings_local
$ python manage.py runserverGo 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.
Prime: static files in the Django accessible directory vespawatch/static/vespawatch should not be edited manually: those are all generated! They are managed in assets 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.jsonto create thenode_modulesdirectory)
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
assets/scss - Update the relevant
.scssfiles - 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.jsonunderdependencies - Install the library with
npm install - Create a new script in
package.jsonunderscriptsto 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
assets/js - Update the relevant
.jsfiles - Copy the files automatically on every changes with
npm run watch:js(or once withnpm run copy:custom-js)
- Go to
assets/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 -l fr $ python manage.py makemessages -d djangojs -l nl -l fr
-
Complete the translations in
locale/*/LC_MESSAGES/django.poandlocale/*/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.