Skip to content

Commit

Permalink
Merge Develop (#250)
Browse files Browse the repository at this point in the history
* Add load river command and use triggers (#226)

* Contributions custom (#248)

* feat: add annex uri in API for Station objects. Allow user to display station name in admin for customcontributions

---------

Co-authored-by: babastienne <bpo@makina-corpus.com>
  • Loading branch information
submarcos and babastienne committed May 15, 2024
1 parent ccabc78 commit 9319ce2
Show file tree
Hide file tree
Showing 128 changed files with 4,481 additions and 1,496 deletions.
6 changes: 3 additions & 3 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[run]
omit =
*/tests*
*/migrations*
*/settings*
*/tests/*
*/migrations/*
*/settings/*
*/venv*
manage.py

Expand Down
46 changes: 8 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
push:
branches:
- master
- develop

release:
types:
- created
Expand All @@ -27,11 +29,12 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Install dependencies
run: |
echo "${{ github.event_name }}! ${{ github.event.action }}"
python -m pip install --upgrade pip
python -m pip install flake8
python -m pip install flake8 -c dev-requirements.txt
- name: Lint with flake8
run: |
flake8 georiviere
Expand Down Expand Up @@ -90,49 +93,16 @@ jobs:
verbose: true
fail_ci_if_error: true # optional (default = false)

build-and-push-dev-image:
runs-on: ubuntu-latest
permissions:
packages: write # required to publish docker image
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
if: ${{(github.base_ref == 'develop')}}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}


build-and-push-image:
runs-on: ubuntu-latest
needs: [flake8, doc_build, unittests]
#needs: [flake8, doc_build, unittests]
needs: [flake8, doc_build]
permissions:
packages: write # required to publish docker image
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
if: ${{ (github.event_name == 'release' && github.event.action == 'created') || (github.ref == 'refs/heads/master' && github.event_name != 'pull_request')}}
if: ${{ (github.event_name == 'release' && github.event.action == 'created') || github.event_name != 'pull_request'}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ RUN apt-get update -qq && apt-get install -y -qq \
USER django

RUN python3.9 -m venv /opt/venv
RUN /opt/venv/bin/pip install --no-cache-dir pip setuptools wheel -U
RUN /opt/venv/bin/pip install --no-cache-dir pip setuptools wheel -U
# geotrek setup fix : it required django before being installed... TODO: fix it in geotrek setup.py
RUN /opt/venv/bin/pip install --no-cache-dir django==2.2.*

Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
deps:
docker compose run --rm web bash -c "pip-compile -q && pip-compile -q dev-requirements.in"
2 changes: 1 addition & 1 deletion dev-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ coverage
django-debug-toolbar
django-extensions
factory-boy
flake8 # WARNING : CI always use last flake8 published version
flake8

# doc
sphinx
Expand Down
65 changes: 39 additions & 26 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#
# This file is autogenerated by pip-compile with python 3.9
# To update, run:
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile dev-requirements.in
#
alabaster==0.7.12
alabaster==0.7.16
# via sphinx
asgiref==3.3.1
# via
# -c requirements.txt
# django
babel==2.9.1
babel==2.14.0
# via sphinx
build==1.2.1
# via pip-tools
certifi==2020.12.5
# via
# -c requirements.txt
Expand Down Expand Up @@ -54,7 +56,7 @@ faker==9.7.1
# via
# -c requirements.txt
# factory-boy
flake8==4.0.1
flake8==7.0.0
# via -r dev-requirements.in
freezegun==1.1.0
# via
Expand All @@ -64,8 +66,12 @@ idna==2.10
# via
# -c requirements.txt
# requests
imagesize==1.3.0
imagesize==1.4.1
# via sphinx
importlib-metadata==7.1.0
# via
# build
# sphinx
jinja2==2.11.3
# via
# -c requirements.txt
Expand All @@ -74,28 +80,29 @@ markupsafe==1.1.1
# via
# -c requirements.txt
# jinja2
mccabe==0.6.1
mccabe==0.7.0
# via flake8
packaging==20.9
# via
# -c requirements.txt
# build
# sphinx
pep517==0.12.0
# via pip-tools
pip-tools==6.5.1
pip-tools==6.10.0
# via -r dev-requirements.in
pycodestyle==2.8.0
pycodestyle==2.11.1
# via flake8
pyflakes==2.4.0
pyflakes==3.2.0
# via flake8
pygments==2.15.0
pygments==2.17.2
# via sphinx
pygraphviz==1.9
pygraphviz==1.11
# via -r dev-requirements.in
pyparsing==2.4.7
# via
# -c requirements.txt
# packaging
pyproject-hooks==1.0.0
# via build
python-dateutil==2.8.1
# via
# -c requirements.txt
Expand All @@ -104,7 +111,6 @@ python-dateutil==2.8.1
pytz==2021.1
# via
# -c requirements.txt
# babel
# django
requests==2.26.0
# via
Expand All @@ -116,43 +122,50 @@ six==1.15.0
# python-dateutil
snowballstemmer==2.2.0
# via sphinx
sphinx==4.4.0
sphinx==5.1.1
# via
# -r dev-requirements.in
# sphinx-rtd-theme
sphinx-rtd-theme==1.0.0
# sphinxcontrib-jquery
sphinx-rtd-theme==2.0.0
# via -r dev-requirements.in
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-applehelp==1.0.8
# via sphinx
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-devhelp==1.0.6
# via sphinx
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-htmlhelp==2.0.5
# via sphinx
sphinxcontrib-jquery==4.1
# via sphinx-rtd-theme
sphinxcontrib-jsmath==1.0.1
# via sphinx
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-qthelp==1.0.7
# via sphinx
sphinxcontrib-serializinghtml==1.1.5
sphinxcontrib-serializinghtml==1.1.10
# via sphinx
sqlparse==0.4.1
# via
# -c requirements.txt
# django
# django-debug-toolbar
tblib==1.7.0
tblib==3.0.0
# via -r dev-requirements.in
text-unidecode==1.3
# via
# -c requirements.txt
# faker
tomli==2.0.0
# via pep517
tomli==2.0.1
# via
# build
# pyproject-hooks
urllib3==1.26.3
# via
# -c requirements.txt
# requests
wheel==0.38.1
wheel==0.43.0
# via pip-tools
zipp==3.18.1
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# pip
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ services:

web:
image: georiviere:latest
user: $UID:$GID
build:
context: .
target: dev
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ CHANGELOG
1.3.0+dev (XXXX-XX-XX)
---------------------

**New features**

- Add load_rivers command
- Create custom contribution types from the admin with specific field schema

**Bug fix**

- Force translation defined in API url /api/portal/<lang> (fix #222)
Expand Down
70 changes: 22 additions & 48 deletions docs/usage/import_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,41 @@ Import data

To import data, you have to run these commands from the server where GeoRiviere-admin is hosted.

Import data
Import altimetry file
---------------------

Put your data file named CoursEau_FXX.shp in ``var/`` folder, and run command
Altimetry should be imported first in GeoRiviere, in order for other imported objects to use DEM to compute altitude.

Custom your import file named import_bdtopage.py et put this file in ``georiviere/``
Put your altimetry file in ``var/`` folder, and run command

.. code-block :: bash
#!/usr/bin/env python
import os
import django
import logging
from django.contrib.gis.gdal import DataSource
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'georiviere.settings')
django.setup()
from geotrek.authent.models import Structure
from django.contrib.gis.geos.collections import MultiLineString
from georiviere.river.models import Stream
# get first structure, adapt with correct structure
structure = Structure.objects.first()
ds = DataSource('var/CoursEau_FXX.shp')
for feat in ds[0][4:]:
try:
# get geos object
geom = feat.geom.geos
# force 2D
geom.dim = 2
name = feat.get('name') or 'No name'
flow = feat.get('flow')
if flow == 1:
flow = 1
elif flow == 2:
flow = 2
else:
flow = 0
stream = Stream.objects.create(structure=structure,
geom=feat.geom.geos,
name=name,
flow=flow)
except Exception as exc:
logging.warn(exc, feat.geom.geos.ewkt)
And run command : `docker compose run --rm web ./import_bdtopage.py`
docker-compose run --rm web ./manage.py loaddem <dem_path>
where ``<dem_path>`` is ``/opt/georiviere-admin/var/my_dem_file.tif``

Import altimetry file
---------------------
If you want to replace an existing DEM, you can add the argument ``--replace`` to the command.

Put your altimetry file in ``var/`` folder, and run command

Import rivers / stream
----------------------

Put your data file (in .shp or .gpkg format) in ``var/`` folder, and run command

.. code-block :: bash
docker-compose run --rm web ./manage.py loaddem <dem_path>
docker-compose run --rm web ./manage.py load_rivers <file_path>
where ``<file_path>`` is ``/opt/georiviere-admin/var/my_stream_file.tif``

Several optional arguments can be used with this command :

.. code-block :: bash
where ``<dem_path>`` is ``/opt/georiviere-admin/var/my_dem_file.tiff``
--flush : to delete all existing rivers in the database before import
--name-attribute <string> : allow to change the column name used to find the name attribute of the river (default is 'nom')
--default-name-attribute <string> : when there is no content in the designated column, this value will be used for the name of the object (default is 'River')
--batch-size <integer> : the rivers are imported by batch, this size can be changed if needed (default is 50)
Import stations from Hub'Eau
Expand Down
Loading

0 comments on commit 9319ce2

Please sign in to comment.