Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add load river command and use triggers #226

Merged
merged 26 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 44 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.13
# via sphinx
asgiref==3.3.1
# via
# -c requirements.txt
# django
babel==2.9.1
babel==2.14.0
# via sphinx
build==1.0.3
# 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==6.1.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.0.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.1.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,55 @@ 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-applehelp
# sphinxcontrib-devhelp
# sphinxcontrib-htmlhelp
# sphinxcontrib-jquery
# sphinxcontrib-qthelp
# sphinxcontrib-serializinghtml
sphinx-rtd-theme==2.0.0
# via -r dev-requirements.in
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-applehelp==1.0.7
# via sphinx
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-devhelp==1.0.5
# via sphinx
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-htmlhelp==2.0.4
# 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.6
# via sphinx
sphinxcontrib-serializinghtml==1.1.5
sphinxcontrib-serializinghtml==1.1.9
# 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.42.0
# via pip-tools
zipp==3.17.0
# 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
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ CHANGELOG
1.3.0+dev (XXXX-XX-XX)
---------------------

**New features**

- add load_rivers command

**Bug fix**

- Force translation defined in API url /api/portal/<lang> (fix #222)
Expand Down
38 changes: 12 additions & 26 deletions georiviere/altimetry.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
from geotrek.altimetry.models import AltimetryMixin as BaseAltimetryMixin

from georiviere.functions import ElevationInfos, Length3D
from geotrek.common.mixins import TimeStampedModelMixin


class AltimetryMixin(BaseAltimetryMixin):
class Meta:
abstract = True
def refresh(self):
# Update object's computed values (reload from database)
if self.pk:
fromdb = self.__class__.objects.get(pk=self.pk)
BaseAltimetryMixin.reload(self, fromdb)
TimeStampedModelMixin.reload(self, fromdb)
return self

def save(self, *args, **kwargs):
super().save(*args, **kwargs)
elevation_infos = self._meta.model.objects.filter(pk=self.pk) \
.annotate(infos=ElevationInfos('geom')).first().infos
draped_geom = elevation_infos.get('draped')
self.geom_3d = draped_geom
self.slope = elevation_infos.get('slope')
self.min_elevation = elevation_infos.get('min_elevation')
self.max_elevation = elevation_infos.get('max_elevation')
self.ascent = elevation_infos.get('positive_gain')
self.descent = elevation_infos.get('negative_gain')
compute_results = self._meta.model.objects.filter(pk=self.pk) \
.annotate(length_3d=Length3D(draped_geom)).first()
self.length = compute_results.length_3d
super().save(force_insert=False,
update_fields=[
'geom_3d',
'slope',
'min_elevation',
'max_elevation',
'ascent',
'descent',
'length'
])
self.refresh()

class Meta:
abstract = True
79 changes: 43 additions & 36 deletions georiviere/contribution/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
InvasiveSpecies, HeritageSpecies, HeritageObservation, FishSpecies,
NaturePollution, TypePollution)

# The json schema is summarize on :
# The json schema is summarized on :
# https://github.com/Georiviere/Georiviere-admin/issues/139
# Depending of the category and type of the contributions, some fields are available or not.
# Depending on the category and type of the contributions, some fields are available or not.
# Here is the generation of the json schema used by the website portal.
# The fields available depending on the type of contributions follow the documentation of jsonschema :
# https://json-schema.org/understanding-json-schema/reference/conditionals.html
Expand All @@ -18,37 +18,43 @@
def get_contribution_properties():
""" Feature properties as form initial data format (name / value) """
# TODO: Use directly field definition for type / title / max length
results = {'name_author': {
'type': "string",
'title': _("Name author"),
"maxLength": 128
}, 'first_name_author': {
'type': "string",
'title': _("First name author"),
"maxLength": 128
}, 'email_author': {
'type': "string",
'title': _("Email"),
'format': "email"
}, 'date_observation': {
'type': "string",
'title': _("Observation's date"),
'format': 'date'
}, 'description': {
'type': "string",
'title': _('Description')
}, 'category': {
"type": "string",
"title": _("Category"),
# TODO: Loop on contribution one to one field to get all possibilities
"enum": [
str(ContributionQuantity._meta.verbose_name.title()),
str(ContributionQuality._meta.verbose_name.title()),
str(ContributionFaunaFlora._meta.verbose_name.title()),
str(ContributionLandscapeElements._meta.verbose_name.title()),
str(ContributionPotentialDamage._meta.verbose_name.title())
],
}
results = {
'name_author': {
'type': "string",
'title': _("Name author"),
"maxLength": 128
},
'first_name_author': {
'type': "string",
'title': _("First name author"),
"maxLength": 128
},
'email_author': {
'type': "string",
'title': _("Email"),
'format': "email"
},
'date_observation': {
'type': "string",
'title': _("Observation's date"),
'format': 'date'
},
'description': {
'type': "string",
'title': _('Description')
},
'category': {
"type": "string",
"title": _("Category"),
# TODO: Loop on contribution one to one field to get all possibilities
"enum": [
str(ContributionQuantity._meta.verbose_name.title()),
str(ContributionQuality._meta.verbose_name.title()),
str(ContributionFaunaFlora._meta.verbose_name.title()),
str(ContributionLandscapeElements._meta.verbose_name.title()),
str(ContributionPotentialDamage._meta.verbose_name.title())
],
}
}
if SeverityType.objects.exists():
results['severity'] = {
Expand Down Expand Up @@ -110,8 +116,7 @@ def get_disruptive_jam(choices, meta):
'jam_type':
{
'type': "string",
'title': str(meta.get_field(
'jam_type').related_model._meta.verbose_name.capitalize()),
'title': str(meta.get_field('jam_type').related_model._meta.verbose_name.capitalize()),
'enum': list(JamType.objects.values_list('label', flat=True))
}
},
Expand All @@ -125,7 +130,9 @@ def get_bank_erosion(choices, meta):
'if': {
'properties': {
'type': {
'const': str(choices.BANK_EROSION.label)}}
'const': str(choices.BANK_EROSION.label)
}
}
},
'then': {
'properties': {
Expand Down
15 changes: 15 additions & 0 deletions georiviere/description/sql/post_10_triggers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TRIGGER description_morphology_10_elevation
BEFORE INSERT OR UPDATE OF geom ON description_morphology
FOR EACH ROW EXECUTE PROCEDURE elevation();

CREATE TRIGGER description_status_10_elevation
BEFORE INSERT OR UPDATE OF geom ON description_status
FOR EACH ROW EXECUTE PROCEDURE elevation();

CREATE TRIGGER description_land_10_elevation
BEFORE INSERT OR UPDATE OF geom ON description_land
FOR EACH ROW EXECUTE PROCEDURE elevation();

CREATE TRIGGER description_usage_10_elevation
BEFORE INSERT OR UPDATE OF geom ON description_usage
FOR EACH ROW EXECUTE PROCEDURE elevation();
3 changes: 3 additions & 0 deletions georiviere/description/sql/post_20_defaults.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE description_morphology ALTER COLUMN full_edge_height SET DEFAULT 0.0;
ALTER TABLE description_morphology ALTER COLUMN full_edge_width SET DEFAULT 0.0;
ALTER TABLE description_morphology ALTER COLUMN description SET DEFAULT '';
8 changes: 4 additions & 4 deletions georiviere/description/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class SatusViewTestCase(TopologyTestCase):
def get_expected_json_attrs(self):
return {
'id': self.obj.pk,
'date_update': '2020-03-17T00:00:00Z',
'date_insert': '2020-03-17T00:00:00Z',
'date_update': self.obj.date_update.isoformat().replace('+00:00', 'Z'),
'date_insert': self.obj.date_insert.isoformat().replace('+00:00', 'Z'),
'description': '',
'length': self.obj.length,
'geom_3d': self.obj.geom_3d.ewkt,
Expand Down Expand Up @@ -147,8 +147,8 @@ class MorphologyViewTestCase(TopologyTestCase):
def get_expected_json_attrs(self):
return {
'id': self.obj.pk,
'date_update': '2020-03-17T00:00:00Z',
'date_insert': '2020-03-17T00:00:00Z',
'date_update': self.obj.date_update.isoformat().replace('+00:00', 'Z'),
'date_insert': self.obj.date_insert.isoformat().replace('+00:00', 'Z'),
'description': '',
'bank_state_left': None,
'bank_state_right': None,
Expand Down
1 change: 1 addition & 0 deletions georiviere/main/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ def ready(self):
from georiviere.river.models import Stream
for model in apps.get_models():
if issubclass(model, MapEntityMixin) and model != Stream:
print("signal for model {}".format(model))
post_save.connect(signals.save_objects_generate_distance_to_source, sender=model)
post_delete.connect(signals.delete_objects_remove_distance_to_source, sender=model)
Loading
Loading