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

💫 [IMPR] Add sensitive areas to mobile API and sync #4490

Merged
merged 14 commits into from
Feb 14, 2025
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
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CHANGELOG
**Improvements**

- Officially support Ubuntu 22.04 debian package.
- Add sensitive areas to mobile API and sync

**Bug fixes**

Expand Down
5 changes: 4 additions & 1 deletion geotrek/api/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-12 12:45+0000\n"
"POT-Creation-Date: 2025-02-13 10:14+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -138,6 +138,9 @@ msgstr ""
msgid "Touristic event types"
msgstr ""

msgid "Sensitive area practices"
msgstr ""

msgid "Sync verifications"
msgstr ""

Expand Down
5 changes: 4 additions & 1 deletion geotrek/api/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-12 12:45+0000\n"
"POT-Creation-Date: 2025-02-13 10:14+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -138,6 +138,9 @@ msgstr ""
msgid "Touristic event types"
msgstr ""

msgid "Sensitive area practices"
msgstr ""

msgid "Sync verifications"
msgstr ""

Expand Down
5 changes: 4 additions & 1 deletion geotrek/api/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-12 12:45+0000\n"
"POT-Creation-Date: 2025-02-13 10:14+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -138,6 +138,9 @@ msgstr ""
msgid "Touristic event types"
msgstr ""

msgid "Sensitive area practices"
msgstr ""

msgid "Sync verifications"
msgstr ""

Expand Down
5 changes: 4 additions & 1 deletion geotrek/api/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-12 12:45+0000\n"
"POT-Creation-Date: 2025-02-13 10:14+0000\n"
"PO-Revision-Date: 2020-10-20 16:33+0000\n"
"Last-Translator: Bastien Potiron <[email protected]>\n"
"Language-Team: French <https://weblate.makina-corpus.net/projects/geotrek-"
Expand Down Expand Up @@ -139,6 +139,9 @@ msgstr "Types de contenu touristique"
msgid "Touristic event types"
msgstr "Types d'événements touristiques"

msgid "Sensitive area practices"
msgstr "Pratiques en zone sensible"

msgid "Sync verifications"
msgstr "Vérification de la synchronisation"

Expand Down
5 changes: 4 additions & 1 deletion geotrek/api/locale/it/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-12 12:45+0000\n"
"POT-Creation-Date: 2025-02-13 10:14+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -138,6 +138,9 @@ msgstr ""
msgid "Touristic event types"
msgstr ""

msgid "Sensitive area practices"
msgstr ""

msgid "Sync verifications"
msgstr ""

Expand Down
5 changes: 4 additions & 1 deletion geotrek/api/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-12 12:45+0000\n"
"POT-Creation-Date: 2025-02-13 10:14+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -138,6 +138,9 @@ msgstr ""
msgid "Touristic event types"
msgstr ""

msgid "Sensitive area practices"
msgstr ""

msgid "Sync verifications"
msgstr ""

Expand Down
11 changes: 11 additions & 0 deletions geotrek/api/management/commands/sync_mobile.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ def sync_trek_touristic_events(self, lang, trek):
name = os.path.join(lang, str(trek.pk), 'touristic_events', '{}.geojson'.format(child.pk))
self.sync_view(lang, view, name, params=params, pk=child.pk)

def sync_trek_sensitive_areas(self, lang, trek):
params = {'format': 'geojson', 'root_pk': trek.pk}
view = TrekViewSet.as_view({'get': 'sensitive_areas'})
name = os.path.join(lang, str(trek.pk), 'sensitive_areas.geojson')
self.sync_view(lang, view, name, params=params, pk=trek.pk)
# Sync sensitive areas of children too
for child in trek.children.annotate(geom_type=GeometryType("geom")).filter(geom_type="LINESTRING"):
name = os.path.join(lang, str(trek.pk), 'sensitive_areas', '{}.geojson'.format(child.pk))
self.sync_view(lang, view, name, params=params, pk=child.pk)

def sync_file(self, name, src_root, url, directory='', zipfile=None):
url = url.strip('/')
src = os.path.join(src_root, name)
Expand Down Expand Up @@ -290,6 +300,7 @@ def sync_trekking(self, lang):
self.sync_trek_pois(lang, trek)
self.sync_trek_touristic_contents(lang, trek)
self.sync_trek_touristic_events(lang, trek)
self.sync_trek_sensitive_areas(lang, trek)
# Sync detail of children too
for child in trek.children.annotate(geom_type=GeometryType("geom")).filter(geom_type="LINESTRING"):
self.sync_geojson(
Expand Down
9 changes: 9 additions & 0 deletions geotrek/api/mobile/serializers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ class Meta:
model = trekking_models.POIType
fields = ('id', 'label', 'pictogram')

if 'geotrek.sensitivity' in settings.INSTALLED_APPS:
from geotrek.sensitivity import models as sensitivity_models

class SportPracticeSerializer(serializers.ModelSerializer):

class Meta:
model = sensitivity_models.SportPractice
fields = ('id', 'name')


class MobileMenuItemListSerializer(serializers.Serializer):

Expand Down
27 changes: 27 additions & 0 deletions geotrek/api/mobile/serializers/sensitivity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from django.conf import settings
from rest_framework import serializers
from rest_framework_gis import serializers as geo_serializers


if 'geotrek.sensitivity' in settings.INSTALLED_APPS:
from geotrek.sensitivity import models as sensitivity_models

class SensitiveAreaListSerializer(geo_serializers.GeoFeatureModelSerializer):
geometry = geo_serializers.GeometryField(read_only=True, precision=7, source='geom2d_transformed')
name = serializers.ReadOnlyField(source='species.name')
description = serializers.ReadOnlyField()
practices = serializers.PrimaryKeyRelatedField(many=True, source='species.practices', read_only=True)
info_url = serializers.URLField(source='species.url')
period = serializers.SerializerMethodField()

class Meta:
model = sensitivity_models.SensitiveArea
id_field = 'pk'
geo_field = 'geometry'
fields = (
'id', 'pk', 'name', 'description', 'practices',
'contact', 'info_url', 'period', 'geometry',
)

def get_period(self, obj):
return [getattr(obj.species, 'period{:02}'.format(p)) for p in range(1, 13)]
Loading
Loading