- PostgreSQL >= 11 + PostGIS
- Python >= 3.9
Fork and clone this repository. Make a copy of the .env
file and adapt it to your environment settings:
cd back
cp .env.sample .env.local
cd ..
The best is to backup and restore a production db. Otherwise, to start from scratch follow this.
Create a geoshop
user if not existing yet, set your password according to your env.local
:
CREATE ROLE geoshop WITH LOGIN PASSWORD <password>;
Then, set up a database in psql:
CREATE DATABASE geoshop OWNER geoshop;
REVOKE ALL ON DATABASE geoshop FROM PUBLIC;
Then connect to the geoshop database \c geoshop
and create extensions:
CREATE EXTENSION postgis;
CREATE EXTENSION unaccent;
CREATE EXTENSION "uuid-ossp";
CREATE SCHEMA geoshop AUTHORIZATION geoshop;
CREATE TEXT SEARCH CONFIGURATION fr (COPY = simple);
ALTER TEXT SEARCH CONFIGURATION fr ALTER MAPPING FOR hword, hword_part, word
WITH unaccent, simple;
Now that the database is ready, you can start backend either with Docker or not.
To ease debug, you can add DEBUG=True
to your env.local
file. Never add this to a container exposed on internet.
Build backend image:
cd back
docker build -t sitn/geoshop-dev-api --build-arg ENV_FILE=.env.local .
If you started with an empty database, run this once in order to create admin account:
docker run --rm --name geoshop --env-file=.env.local sitn/geoshop-dev-api python manage.py fixturize
Now you can run it with:
docker run -d --rm --name geoshop --env-file=.env.local -p 8000:8000 -v ${PWD}:/app/geoshop_back sitn/geoshop-dev-api gunicorn --reload wsgi -b :8000
You should be able to visit the API at http://localhost:8000.
Run tests:
docker run --rm --env-file=.env.local -v ${PWD}:/app/geoshop_back sitn/geoshop-dev-api python manage.py test api
Make messages for translation:
docker run --rm --env-file=.env.local -v ${PWD}:/app/geoshop_back:rw sitn/geoshop-dev-api python manage.py makemessages -l fr
Stop the server:
docker stop geoshop
⚠️ No longer maintained: Installing GDAL in windows is really painfull, use docker for backend.
If not using docker, additionnal packages are required:
- pipenv (pip install pipenv)
- GDAL 2.4 (see instructions below to install it in your venv)
Install the app. If you want your venv
to be inside your project directory, you need to set PIPENV_VENV_IN_PROJECT
environment variable, otherwise it'll go to your profile, if you want DEBUG
to be enabled, change it in settings.py
file but never commit it with debug enabled:
cd back
$env:PIPENV_VENV_IN_PROJECT="True"
pipenv install --dev # installs everything needed
pipenv shell # activates venv and reads .env file
Download the GDAL 2.4 wheel (3.X isn't supported yet by Django) on this page: https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal. For example, if you have Python 3.6 64bit, choose GDAL‑2.4.1‑cp36‑cp36m‑win_amd64.whl
.
Then install it weather system wide or in your venv (the example below will show the venv variant and expects you have your venv activated):
pip install path\to\your\GDAL-2.4XXXX.whl
You'll then need to add GDAL dll to your PATH if you installed it system wide. You can get the dll path with:
python
from pathlib import Path, PureWindowsPath
from osgeo import gdal
print(PureWindowsPath(gdal.__file__).parent)
Otherwise, if you installed it in your venv, configure .env
properly.
You should now be able to run migrations:
python manage.py migrate
If you're starting with a fresh new database you'll need to create an user or restore a dump:
python manage.py createsuperuser --email admin@example.com --username admin
Your database should be ready, now you can run the backend:
python manage.py runserver
Translations can be generated, static files collected with:
python manage.py compilemessages --locale=fr
python .\manage.py collectstatic
Then, set DEBUG
to True
in back/settings.py
and you can finally run the server:
python manage.py runserver
⚠️ DO NOT COMMIT settings.py withDEBUG
set toTrue
!
python manage.py test api
Install the current LTS version of Nodejs.
Install @angular/cli and typescript globally
npm install -g @angular/cli typescript
Install the dependances of the frontend
cd front
npm install
Edit the settings, the file is /front/copy-config.ps1
Typicall values for dev purposes are:
"apiUrl": "https://sitn.ne.ch/geoshop2_prepub_api",
"mediaUrl": "https://sitn.ne.ch/geoshop2_prepub_media/images",
To start the debug of the frontend
npm start
- Will run the batch /front/copy-config.ps1
- Will automatically run chrome with insecure flags to allow CORS request
- Chrome browser will be waiting with Geoshop2
Create an env.prod
file base on env.sample
.
.\scripts\4_deploy_prod.ps1
Create a scheduled task that runs scripts/geoshop_clean_orders.ps1
every month.
More info on bookstack
Go to https://update.angular.io/?v=16.0-17.0 and check there are not manual steps to be done.
Then follow instructions. After upgrading, some packages will need to be upgraded according to angular version you will be using. For instance, if you'll upgrade to version 17, you need to target version 17 for these packages:
ng update @ngrx/store@17 angular-split@17
After, you can update other packages:
ng update lodash-es rxjs tslib zone.js
Finally, update those related to OpenLayers:
ng update ol ol-ext ol-geocoder proj4
Then all the front-end tests should be done.