From b0ca33ee0d1dc68e4b017fc30536e3daedef3429 Mon Sep 17 00:00:00 2001 From: Bastien Potiron Date: Fri, 10 Nov 2023 11:53:29 +0100 Subject: [PATCH 1/5] Change translation to match name given by PO --- .../locale/fr/LC_MESSAGES/django.po | 11 ++++------- .../migrations/0009_auto_20231110_1214.py | 17 +++++++++++++++++ georiviere/contribution/models.py | 4 ++-- 3 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 georiviere/contribution/migrations/0009_auto_20231110_1214.py diff --git a/georiviere/contribution/locale/fr/LC_MESSAGES/django.po b/georiviere/contribution/locale/fr/LC_MESSAGES/django.po index a70ee477..aefa84b7 100644 --- a/georiviere/contribution/locale/fr/LC_MESSAGES/django.po +++ b/georiviere/contribution/locale/fr/LC_MESSAGES/django.po @@ -109,11 +109,11 @@ msgstr "Aucun type" msgid "Feedback from {email}" msgstr "Retour utilisateur depuis {email}" -msgid "Contribution potential damage type" -msgstr "Type de contibution dégats potentiels" +msgid "Landing type" +msgstr "Type d'atterrissement" -msgid "Contribution potential damage types" -msgstr "Contribution Dégats potentiels" +msgid "Landing types" +msgstr "Types d'atterrissement" msgid "Jam type" msgstr "Type d'embâcle" @@ -157,9 +157,6 @@ msgstr "Mortalité piscicole" msgid "Trampling by livestock (impacting)" msgstr "Piétinement par le bétail (impactant)" -msgid "Landing type" -msgstr "Type d'atterrissement" - msgid "Excessive cutting length (in meters)" msgstr "Longueur coupe abusive (en mètres)" diff --git a/georiviere/contribution/migrations/0009_auto_20231110_1214.py b/georiviere/contribution/migrations/0009_auto_20231110_1214.py new file mode 100644 index 00000000..d8971268 --- /dev/null +++ b/georiviere/contribution/migrations/0009_auto_20231110_1214.py @@ -0,0 +1,17 @@ +# Generated by Django 3.1.14 on 2023-11-10 12:14 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('contribution', '0008_auto_20230731_1304'), + ] + + operations = [ + migrations.AlterModelOptions( + name='landingtype', + options={'verbose_name': 'Landing type', 'verbose_name_plural': 'Landing types'}, + ), + ] diff --git a/georiviere/contribution/models.py b/georiviere/contribution/models.py index e5fdc406..3009a5a4 100644 --- a/georiviere/contribution/models.py +++ b/georiviere/contribution/models.py @@ -224,8 +224,8 @@ class LandingType(models.Model): label = models.CharField(max_length=128, verbose_name=_("Label"), unique=True) class Meta: - verbose_name = _("Contribution potential damage type") - verbose_name_plural = _("Contribution potential damage types") + verbose_name = _("Landing type") + verbose_name_plural = _("Landing types") def __str__(self): return self.label From 83ba20a3626e64db898210292bdde44ff200f970 Mon Sep 17 00:00:00 2001 From: Bastien Potiron Date: Fri, 10 Nov 2023 11:54:12 +0100 Subject: [PATCH 2/5] Add fixtures to contributions in order to pre-fill values for forms --- georiviere/contribution/fixtures/basic.json | 512 ++++++++++++++++++-- 1 file changed, 480 insertions(+), 32 deletions(-) diff --git a/georiviere/contribution/fixtures/basic.json b/georiviere/contribution/fixtures/basic.json index 8fcee7df..7e13c02e 100644 --- a/georiviere/contribution/fixtures/basic.json +++ b/georiviere/contribution/fixtures/basic.json @@ -1,38 +1,486 @@ [ -{ - "model": "contribution.contributionstatus", - "pk": 1, - "fields": { - "label": "Informé", + { + "model": "contribution.severitytype", + "pk": 1, + "fields": { + "label": "Faible" + } + }, + { + "model": "contribution.severitytype", + "pk": 2, + "fields": { + "label": "Modéré" + } + }, + { + "model": "contribution.severitytype", + "pk": 3, + "fields": { + "label": "Fort" + } + }, + { + "model": "contribution.contributionstatus", + "pk": 1, + "fields": { "date_insert": "2023-05-09T15:15:30.143Z", - "date_update": "2022-03-09T15:15:30.143Z" - } -}, -{ - "model": "contribution.contributionstatus", - "pk": 2, - "fields": { - "label": "En cours de traitement", + "date_update": "2022-03-09T15:15:30.143Z", + "label": "Informé" + } + }, + { + "model": "contribution.contributionstatus", + "pk": 2, + "fields": { "date_insert": "2023-05-09T15:15:30.143Z", - "date_update": "2022-03-09T15:15:30.143Z" - } -}, -{ - "model": "contribution.contributionstatus", - "pk": 3, - "fields": { - "label": "Traité", + "date_update": "2022-03-09T15:15:30.143Z", + "label": "En cours de traitement" + } + }, + { + "model": "contribution.contributionstatus", + "pk": 3, + "fields": { "date_insert": "2023-05-09T15:15:30.143Z", - "date_update": "2022-03-09T15:15:30.143Z" - } -}, -{ - "model": "contribution.contributionstatus", - "pk": 4, - "fields": { - "label": "Retour au contributeur", + "date_update": "2022-03-09T15:15:30.143Z", + "label": "Traité" + } + }, + { + "model": "contribution.contributionstatus", + "pk": 4, + "fields": { "date_insert": "2023-05-09T15:15:30.143Z", - "date_update": "2022-03-09T15:15:30.143Z" + "date_update": "2022-03-09T15:15:30.143Z", + "label": "Retour au contributeur" + } + }, + { + "model": "contribution.landingtype", + "pk": 1, + "fields": { + "label": "Partiel en berge" + } + }, + { + "model": "contribution.landingtype", + "pk": 2, + "fields": { + "label": "Partiel au milieu du lit" + } + }, + { + "model": "contribution.landingtype", + "pk": 3, + "fields": { + "label": "Total" + } + }, + { + "model": "contribution.jamtype", + "pk": 1, + "fields": { + "label": "Partiel en berge" + } + }, + { + "model": "contribution.jamtype", + "pk": 2, + "fields": { + "label": "Partiel au milieu du lit" + } + }, + { + "model": "contribution.jamtype", + "pk": 3, + "fields": { + "label": "Total" + } + }, + { + "model": "contribution.diseasetype", + "pk": 1, + "fields": { + "label": "Excroissances blanchâtres" + } + }, + { + "model": "contribution.diseasetype", + "pk": 2, + "fields": { + "label": "Léthargie" + } + }, + { + "model": "contribution.diseasetype", + "pk": 3, + "fields": { + "label": "Points blancs" + } + }, + { + "model": "contribution.diseasetype", + "pk": 4, + "fields": { + "label": "Ulcérations" + } + }, + { + "model": "contribution.deadspecies", + "pk": 1, + "fields": { + "label": "Barbeau" + } + }, + { + "model": "contribution.deadspecies", + "pk": 2, + "fields": { + "label": "Blageon" + } + }, + { + "model": "contribution.deadspecies", + "pk": 3, + "fields": { + "label": "Brochet" + } + }, + { + "model": "contribution.deadspecies", + "pk": 4, + "fields": { + "label": "Chabot" + } + }, + { + "model": "contribution.deadspecies", + "pk": 5, + "fields": { + "label": "Chevesne" + } + }, + { + "model": "contribution.deadspecies", + "pk": 6, + "fields": { + "label": "Goujon" + } + }, + { + "model": "contribution.deadspecies", + "pk": 7, + "fields": { + "label": "Lamproie" + } + }, + { + "model": "contribution.deadspecies", + "pk": 8, + "fields": { + "label": "Loche franche" + } + }, + { + "model": "contribution.deadspecies", + "pk": 9, + "fields": { + "label": "Lotte" + } + }, + { + "model": "contribution.deadspecies", + "pk": 10, + "fields": { + "label": "Ombre commun" + } + }, + { + "model": "contribution.deadspecies", + "pk": 11, + "fields": { + "label": "Spirlin" + } + }, + { + "model": "contribution.deadspecies", + "pk": 12, + "fields": { + "label": "Toxostome" + } + }, + { + "model": "contribution.deadspecies", + "pk": 13, + "fields": { + "label": "Truite fario" + } + }, + { + "model": "contribution.deadspecies", + "pk": 14, + "fields": { + "label": "Vairon" + } + }, + { + "model": "contribution.deadspecies", + "pk": 15, + "fields": { + "label": "Vandoise" + } + }, + { + "model": "contribution.invasivespecies", + "pk": 1, + "fields": { + "label": "Ecrevisse américaine" + } + }, + { + "model": "contribution.invasivespecies", + "pk": 2, + "fields": { + "label": "Ambroisie à feuille d'armoise" + } + }, + { + "model": "contribution.invasivespecies", + "pk": 3, + "fields": { + "label": "Balsamine de l'Himalaya" + } + }, + { + "model": "contribution.invasivespecies", + "pk": 4, + "fields": { + "label": "Berce du caucase" + } + }, + { + "model": "contribution.invasivespecies", + "pk": 5, + "fields": { + "label": "Buddleia (ou arbre à papillons)" + } + }, + { + "model": "contribution.invasivespecies", + "pk": 6, + "fields": { + "label": "Elodée du canada" + } + }, + { + "model": "contribution.invasivespecies", + "pk": 7, + "fields": { + "label": "Renouées asiatiques" + } + }, + { + "model": "contribution.invasivespecies", + "pk": 8, + "fields": { + "label": "Solidage (ou verge d'or)" + } + }, + { + "model": "contribution.heritagespecies", + "pk": 1, + "fields": { + "label": "Écrevisse à pattes blanches" + } + }, + { + "model": "contribution.heritagespecies", + "pk": 2, + "fields": { + "label": "Salamandre tachetée" + } + }, + { + "model": "contribution.heritagespecies", + "pk": 3, + "fields": { + "label": "Sonneur à ventre jaune" + } + }, + { + "model": "contribution.heritagespecies", + "pk": 4, + "fields": { + "label": "Castor" + } + }, + { + "model": "contribution.heritagespecies", + "pk": 5, + "fields": { + "label": "Loutre" + } + }, + { + "model": "contribution.heritageobservation", + "pk": 1, + "fields": { + "label": "Visuel" + } + }, + { + "model": "contribution.heritageobservation", + "pk": 2, + "fields": { + "label": "Indice de présence" + } + }, + { + "model": "contribution.fishspecies", + "pk": 1, + "fields": { + "label": "Barbeau" + } + }, + { + "model": "contribution.fishspecies", + "pk": 2, + "fields": { + "label": "Blageon" + } + }, + { + "model": "contribution.fishspecies", + "pk": 3, + "fields": { + "label": "Brochet" + } + }, + { + "model": "contribution.fishspecies", + "pk": 4, + "fields": { + "label": "Chabot" + } + }, + { + "model": "contribution.fishspecies", + "pk": 5, + "fields": { + "label": "Chevesne" + } + }, + { + "model": "contribution.fishspecies", + "pk": 6, + "fields": { + "label": "Goujon" + } + }, + { + "model": "contribution.fishspecies", + "pk": 7, + "fields": { + "label": "Lamproie" + } + }, + { + "model": "contribution.fishspecies", + "pk": 8, + "fields": { + "label": "Loche franche" + } + }, + { + "model": "contribution.fishspecies", + "pk": 9, + "fields": { + "label": "Lotte" + } + }, + { + "model": "contribution.fishspecies", + "pk": 10, + "fields": { + "label": "Ombre commun" + } + }, + { + "model": "contribution.fishspecies", + "pk": 11, + "fields": { + "label": "Spirlin" + } + }, + { + "model": "contribution.fishspecies", + "pk": 12, + "fields": { + "label": "Toxostome" + } + }, + { + "model": "contribution.fishspecies", + "pk": 13, + "fields": { + "label": "Truite fario" + } + }, + { + "model": "contribution.fishspecies", + "pk": 14, + "fields": { + "label": "Vairon" + } + }, + { + "model": "contribution.fishspecies", + "pk": 15, + "fields": { + "label": "Vandoise" + } + }, + { + "model": "contribution.naturepollution", + "pk": 1, + "fields": { + "label": "Déchets" + } + }, + { + "model": "contribution.naturepollution", + "pk": 2, + "fields": { + "label": "Effluents d'élevage" + } + }, + { + "model": "contribution.naturepollution", + "pk": 3, + "fields": { + "label": "Hydrocarbures" + } + }, + { + "model": "contribution.naturepollution", + "pk": 4, + "fields": { + "label": "Présence abondante de mousse" + } + }, + { + "model": "contribution.typepollution", + "pk": 1, + "fields": { + "label": "Visible" + } + }, + { + "model": "contribution.typepollution", + "pk": 2, + "fields": { + "label": "Olfactive" + } } -} -] + ] From cab50f4310a2ddd812389f7a23968f78b8e1a8f0 Mon Sep 17 00:00:00 2001 From: Bastien Potiron Date: Fri, 10 Nov 2023 12:32:34 +0100 Subject: [PATCH 3/5] [FIX] Allow user to delete Contribution (fix #217) --- georiviere/contribution/forms.py | 1 - georiviere/contribution/tests/test_views.py | 6 ++++++ georiviere/contribution/views.py | 10 ++++------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/georiviere/contribution/forms.py b/georiviere/contribution/forms.py index 75bfbc26..2403ed84 100644 --- a/georiviere/contribution/forms.py +++ b/georiviere/contribution/forms.py @@ -10,7 +10,6 @@ class ContributionForm(autocomplete.FutureModelForm, CommonForm): - can_delete = False geomfields = ['geom'] linked_object = autocomplete.Select2GenericForeignKeyModelField( diff --git a/georiviere/contribution/tests/test_views.py b/georiviere/contribution/tests/test_views.py index 78a456c6..baf8720d 100644 --- a/georiviere/contribution/tests/test_views.py +++ b/georiviere/contribution/tests/test_views.py @@ -103,5 +103,11 @@ def test_crud_status(self): response = self.client.get(obj.get_update_url()) self.assertEqual(response.status_code, 302) + # Test to delete object + self.login() + + response = self.client.get(obj.get_update_url()) + self.assertEqual(response.status_code, 200) + def test_document_export(self): pass diff --git a/georiviere/contribution/views.py b/georiviere/contribution/views.py index b12300e5..f65e679d 100644 --- a/georiviere/contribution/views.py +++ b/georiviere/contribution/views.py @@ -1,5 +1,5 @@ from mapentity.views import (MapEntityList, MapEntityDetail, MapEntityFormat, MapEntityLayer, MapEntityJsonList, - MapEntityUpdate) + MapEntityUpdate, MapEntityDelete) from georiviere.contribution.filters import ContributionFilterSet @@ -36,8 +36,6 @@ class ContributionUpdate(MapEntityUpdate): model = Contribution form_class = ContributionForm - def get_form_kwargs(self): - kwargs = super().get_form_kwargs() - # We don't want to allow to delete contributions - kwargs['can_delete'] = False - return kwargs + +class ContributionDelete(MapEntityDelete): + model = Contribution From 0c40f9e58b0806ef8bff3dbad788208d94046ba4 Mon Sep 17 00:00:00 2001 From: Bastien Potiron Date: Fri, 10 Nov 2023 12:43:07 +0100 Subject: [PATCH 4/5] Return JamType list instead of text field (fix #199) --- georiviere/contribution/schema.py | 1 + 1 file changed, 1 insertion(+) diff --git a/georiviere/contribution/schema.py b/georiviere/contribution/schema.py index 98f5f60f..f7adc013 100644 --- a/georiviere/contribution/schema.py +++ b/georiviere/contribution/schema.py @@ -112,6 +112,7 @@ def get_disruptive_jam(choices, meta): 'type': "string", 'title': str(meta.get_field( 'jam_type').verbose_name.capitalize()), + 'enum': list(JamType.objects.values_list('label', flat=True)) } }, } From 3ee179c0cae60dca17bb45616f647cb149178510 Mon Sep 17 00:00:00 2001 From: Bastien Potiron Date: Fri, 10 Nov 2023 13:04:17 +0100 Subject: [PATCH 5/5] Fix translations for fields that were in English in fr mode Related ticket : https://github.com/orgs/Georiviere/projects/2/views/1?pane=issue&itemId=33770630 --- .../locale/fr/LC_MESSAGES/django.po | 16 ++++++++---- georiviere/contribution/schema.py | 25 ++++++++----------- .../data/json_schema_base_contribution.json | 17 ++++++++----- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/georiviere/contribution/locale/fr/LC_MESSAGES/django.po b/georiviere/contribution/locale/fr/LC_MESSAGES/django.po index aefa84b7..9e554886 100644 --- a/georiviere/contribution/locale/fr/LC_MESSAGES/django.po +++ b/georiviere/contribution/locale/fr/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-09-15 17:01+0000\n" +"POT-Creation-Date: 2023-11-10 12:01+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -238,16 +238,16 @@ msgid "contributions quantity" msgstr "Contributions quantité" msgid "Nature pollution" -msgstr "Nature pollution" +msgstr "Nature de la pollution" msgid "Natures pollution" -msgstr "Natures pollution" +msgstr "Natures des pollutions" msgid "Type pollution" -msgstr "Type pollution" +msgstr "Type de pollution" msgid "Types pollution" -msgstr "Types pollution" +msgstr "Types de pollution" msgid "Algal development" msgstr "Développement algal" @@ -315,6 +315,12 @@ msgstr "Contentieux" msgid "Knowledge" msgstr "Connaissance" +msgid "Observed species" +msgstr "Espèce observée" + +msgid "Observation type" +msgstr "Type d'observation" + msgid "None" msgstr "Aucun" diff --git a/georiviere/contribution/schema.py b/georiviere/contribution/schema.py index f7adc013..0c85d301 100644 --- a/georiviere/contribution/schema.py +++ b/georiviere/contribution/schema.py @@ -69,7 +69,7 @@ def get_landing(choices, meta): 'landing_type': { 'type': "string", - 'title': str(meta.get_field('landing_type').verbose_name.capitalize()), + 'title': str(meta.get_field('landing_type').related_model._meta.verbose_name.capitalize()), 'enum': list(LandingType.objects.values_list('label', flat=True)) } }, @@ -111,7 +111,7 @@ def get_disruptive_jam(choices, meta): { 'type': "string", 'title': str(meta.get_field( - 'jam_type').verbose_name.capitalize()), + 'jam_type').related_model._meta.verbose_name.capitalize()), 'enum': list(JamType.objects.values_list('label', flat=True)) } }, @@ -175,7 +175,7 @@ def get_fish_diseases(choices, meta): { 'type': "string", 'title': str(meta.get_field( - 'disease_type').verbose_name.capitalize()), + 'disease_type').related_model._meta.verbose_name.capitalize()), 'enum': list(DiseaseType.objects.values_list('label', flat=True)) } }, @@ -196,8 +196,7 @@ def get_fish_mortality(choices, meta): if DeadSpecies.objects.exists(): fish_mortality_property['dead_species'] = { 'type': "string", - 'title': str(meta.get_field( - 'dead_species').verbose_name.capitalize()), + 'title': _("Observed species"), 'enum': list(DeadSpecies.objects.values_list('label', flat=True)) } fish_mortality = { @@ -265,8 +264,7 @@ def get_invasive_species(choices, meta): if InvasiveSpecies.objects.exists(): invasive_species_property['invasive_species'] = { 'type': "string", - 'title': str(meta.get_field( - 'invasive_species').verbose_name.capitalize()), + 'title': _("Observed species"), 'enum': list(InvasiveSpecies.objects.values_list('label', flat=True)) } invasive_species = { @@ -294,15 +292,13 @@ def get_heritage_species(choices, meta): if HeritageSpecies.objects.exists(): heritage_species_property['heritage_species'] = { 'type': "string", - 'title': str(meta.get_field( - 'heritage_species').verbose_name.capitalize()), + 'title': _("Observed species"), 'enum': list(HeritageSpecies.objects.values_list('label', flat=True)) } if HeritageObservation.objects.exists(): heritage_species_property['heritage_observation'] = { 'type': "string", - 'title': str(meta.get_field( - 'heritage_observation').verbose_name.capitalize()), + 'title': _("Observation type"), 'enum': list(HeritageObservation.objects.values_list('label', flat=True)) } heritage_species = { @@ -330,8 +326,7 @@ def get_fish_species(choices, meta): if FishSpecies.objects.exists(): fish_species_property['fish_species'] = { 'type': "string", - 'title': str(meta.get_field( - 'fish_species').verbose_name.capitalize()), + 'title': _("Observed species"), 'enum': list(FishSpecies.objects.values_list('label', flat=True)) } fish_species = { @@ -430,14 +425,14 @@ def get_pollution(choices, meta): pollution_property['nature_pollution'] = { 'type': "string", 'title': str(meta.get_field( - 'nature_pollution').verbose_name.capitalize()), + 'nature_pollution').related_model._meta.verbose_name.capitalize()), 'enum': list(NaturePollution.objects.values_list('label', flat=True)) } if TypePollution.objects.exists(): pollution_property['type_pollution'] = { 'type': "string", 'title': str(meta.get_field( - 'type_pollution').verbose_name.capitalize()), + 'type_pollution').related_model._meta.verbose_name.capitalize()), 'enum': list(TypePollution.objects.values_list('label', flat=True)) } pollution = { diff --git a/georiviere/portal/tests/data/json_schema_base_contribution.json b/georiviere/portal/tests/data/json_schema_base_contribution.json index 8a9d8422..a562fa96 100644 --- a/georiviere/portal/tests/data/json_schema_base_contribution.json +++ b/georiviere/portal/tests/data/json_schema_base_contribution.json @@ -150,7 +150,7 @@ }, "dead_species": { "type": "string", - "title": "Dead species", + "title": "Observed species", "enum": [ "Dead species 0", "Dead species 1", @@ -194,7 +194,12 @@ "properties": { "jam_type": { "type": "string", - "title": "Jam type" + "title": "Jam type", + "enum": [ + "Jam type 0", + "Jam type 1", + "Jam type 2" + ] } } } @@ -262,7 +267,7 @@ }, "invasive_species": { "type": "string", - "title": "Invasive species", + "title": "Observed species", "enum": [ "Invasive species 0", "Invasive species 1", @@ -288,7 +293,7 @@ }, "heritage_species": { "type": "string", - "title": "Heritage species", + "title": "Observed species", "enum": [ "Heritage species 0", "Heritage species 1", @@ -297,7 +302,7 @@ }, "heritage_observation": { "type": "string", - "title": "Heritage observation", + "title": "Observation type", "enum": [ "Heritage observation 0", "Heritage observation 1", @@ -323,7 +328,7 @@ }, "fish_species": { "type": "string", - "title": "Fish species", + "title": "Observed species", "enum": [ "Fish species 0", "Fish species 1",