diff --git a/docs/changelog.rst b/docs/changelog.rst
index d4dc7f2c25..5254c5a16c 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -12,6 +12,7 @@ CHANGELOG
**Improvements**
- Add rules fixture on sensitive area (#3470)
+- Update maintenance date to have begin & end date (#3825)
**Documentation**
diff --git a/geotrek/feedback/fixtures/test-integration.json b/geotrek/feedback/fixtures/test-integration.json
index 50ae601bc2..d85421001a 100644
--- a/geotrek/feedback/fixtures/test-integration.json
+++ b/geotrek/feedback/fixtures/test-integration.json
@@ -246,7 +246,7 @@
"pk": 1,
"fields": {
"label": "Intervention résolue",
- "text": "Pris en charge par ##supervisor## le ##intervention_date##"
+ "text": "Pris en charge par ##supervisor## le ##intervention_begin_date##"
}
},
{
@@ -299,7 +299,7 @@
],
"target_id": 12,
"name": "Intervention on report",
- "date": "2022-05-17",
+ "begin_date": "2022-05-17",
"status": 3,
"date_insert": "2012-05-17T14:33:34.307Z",
"date_update": "2012-05-17T14:33:34.307Z"
diff --git a/geotrek/feedback/static/feedback/workflow.js b/geotrek/feedback/static/feedback/workflow.js
index 61827824a6..f60820c823 100644
--- a/geotrek/feedback/static/feedback/workflow.js
+++ b/geotrek/feedback/static/feedback/workflow.js
@@ -65,7 +65,7 @@ function display_predefined_email_in_email_field() {
} else {
text = predefined_emails[selected]["text"];
text = text.replace(/##supervisor##/g, resolved_intervention_info["username"]);
- text = text.replace(/##intervention_date##/g, resolved_intervention_info["date"]);
+ text = text.replace(/##intervention_begin_date##/g, resolved_intervention_info["begin_date"]);
$('#id_message_sentinel').val(text);
$('#id_message_administrators').val(text);
}
diff --git a/geotrek/feedback/templates/feedback/report_detail_attributes.html b/geotrek/feedback/templates/feedback/report_detail_attributes.html
index cae3d272c1..2b91ae22b3 100644
--- a/geotrek/feedback/templates/feedback/report_detail_attributes.html
+++ b/geotrek/feedback/templates/feedback/report_detail_attributes.html
@@ -125,7 +125,7 @@
{% trans "Attributes" %}
{% if perms.maintenance.add_intervention %}
{% trans "Intervention" %}
- {% with columns="name,status,stake,total_cost,date" %}
+ {% with columns="name,status,stake,total_cost,begin_date" %}
{% valuetable report.interventions.all columns=columns %}
{% endwith %}
{% if not suricate_workflow_enabled %}
diff --git a/geotrek/feedback/templatetags/feedback_tags.py b/geotrek/feedback/templatetags/feedback_tags.py
index 3a92767d23..c3b427ccca 100644
--- a/geotrek/feedback/templatetags/feedback_tags.py
+++ b/geotrek/feedback/templatetags/feedback_tags.py
@@ -63,7 +63,7 @@ def resolved_intervention_info(report):
username = user.username
resolved_intervention_info = {
- "date": report.interventions.first().date.strftime("%d/%m/%Y") if report.interventions else None,
+ "date": report.interventions.first().begin_date.strftime("%d/%m/%Y") if report.interventions else None,
"username": username
}
return json.dumps(resolved_intervention_info)
diff --git a/geotrek/feedback/tests/test_forms.py b/geotrek/feedback/tests/test_forms.py
index 16b6e97b69..d839d1a53a 100644
--- a/geotrek/feedback/tests/test_forms.py
+++ b/geotrek/feedback/tests/test_forms.py
@@ -42,7 +42,7 @@ def setUpTestData(cls):
cls.filed_report_1 = ReportFactory(status=cls.filed_status, external_uuid=uuid.uuid4())
cls.filed_report_2 = ReportFactory(status=cls.filed_status, external_uuid=uuid.uuid4())
cls.waiting_report = ReportFactory(status=cls.waiting_status, uses_timers=True, external_uuid=uuid.uuid4())
- cls.intervention = ReportInterventionFactory(date=datetime(year=1997, month=4, day=4).date())
+ cls.intervention = ReportInterventionFactory(begin_date=datetime(year=1997, month=4, day=4).date())
cls.waiting_report = ReportFactory(status=cls.waiting_status, uses_timers=True, external_uuid=uuid.uuid4())
cls.solved_intervention_report = ReportFactory(status=cls.solved_intervention_status, external_uuid=uuid.uuid4())
cls.predefined_email_1 = PredefinedEmailFactory()
@@ -257,7 +257,7 @@ def test_workflow_program_step(self):
user = SuperUserFactory(username="admin", password="dadadad")
data = {
'name': "test_interv",
- 'date': "2025-12-12",
+ 'begin_date': "2025-12-12",
'status': 2,
'structure': user.profile.structure.pk,
}
@@ -285,7 +285,7 @@ def test_solving_report_intervention(self, mocked_post):
user = SuperUserFactory(username="admin", password="dadadad")
data = {
'name': interv.name,
- 'date': interv.date,
+ 'begin_date': interv.begin_date,
'status': 3, # pk for "Terminée" from fixtures
'structure': user.profile.structure.pk
}
diff --git a/geotrek/feedback/tests/test_template_tags.py b/geotrek/feedback/tests/test_template_tags.py
index 5086590da8..cf1d1555e6 100644
--- a/geotrek/feedback/tests/test_template_tags.py
+++ b/geotrek/feedback/tests/test_template_tags.py
@@ -22,7 +22,7 @@ def setUpTestData(cls):
cls.user2 = UserFactory(username="Kurt")
UserProfileFactory.create(user=cls.user2)
cls.solved_status = ReportStatusFactory(identifier='solved_intervention', color="#448654")
- cls.intervention_solved_1 = ReportInterventionFactory(date=datetime(year=1997, month=4, day=4).date())
+ cls.intervention_solved_1 = ReportInterventionFactory(begin_date=datetime(year=1997, month=4, day=4).date())
# Simulate user created intervention
LogEntry.objects.log_action(
user_id=cls.user1.pk,
@@ -36,7 +36,7 @@ def setUpTestData(cls):
cls.status_1 = cls.report_1.status
cls.report_1.status = cls.solved_status
cls.report_1.save()
- cls.intervention_solved_2 = ReportInterventionFactory(date=datetime(year=1997, month=5, day=4).date())
+ cls.intervention_solved_2 = ReportInterventionFactory(begin_date=datetime(year=1997, month=5, day=4).date())
# Simulate user created intervention
LogEntry.objects.log_action(
user_id=cls.user2.pk,
diff --git a/geotrek/infrastructure/filters.py b/geotrek/infrastructure/filters.py
index e397777700..13f9c7d982 100644
--- a/geotrek/infrastructure/filters.py
+++ b/geotrek/infrastructure/filters.py
@@ -36,6 +36,6 @@ class Meta(StructureRelatedFilterSet.Meta):
def filter_intervention_year(self, qs, name, value):
infrastructure_ct = ContentType.objects.get_for_model(Infrastructure)
- interventions = Intervention.objects.filter(target_type=infrastructure_ct, date__year__in=value) \
+ interventions = Intervention.objects.filter(target_type=infrastructure_ct, begin_date__year__in=value) \
.values_list('target_id', flat=True)
return qs.filter(id__in=interventions).distinct()
diff --git a/geotrek/infrastructure/tests/test_filters.py b/geotrek/infrastructure/tests/test_filters.py
index 54493a5e2d..806f9c2e89 100644
--- a/geotrek/infrastructure/tests/test_filters.py
+++ b/geotrek/infrastructure/tests/test_filters.py
@@ -81,11 +81,11 @@ def test_intervention_filter(self):
# Bad signage: intervention with wrong year
bad_topo = self.factory()
- InterventionFactory(target=bad_topo, date=bad_date_year)
+ InterventionFactory(target=bad_topo, begin_date=bad_date_year)
# Good signage: intervention with the good year
good_topo = self.factory()
- InterventionFactory(target=good_topo, date=good_date_year)
+ InterventionFactory(target=good_topo, begin_date=good_date_year)
data = {
'intervention_year': year
@@ -105,11 +105,11 @@ def test_duplicate_implantation_year_filter(self):
# Bad signage: intervention with wrong year
topo_1 = self.factory()
- InterventionFactory(target=topo_1, date=year_t)
+ InterventionFactory(target=topo_1, begin_date=year_t)
# Good signage: intervention with the good year
topo_2 = self.factory()
- InterventionFactory(target=topo_2, date=year_t)
+ InterventionFactory(target=topo_2, begin_date=year_t)
response = self.client.get(model.get_list_url())
self.assertContains(response, '', count=1)
diff --git a/geotrek/maintenance/filters.py b/geotrek/maintenance/filters.py
index 7234b5932e..06d1b8afb4 100644
--- a/geotrek/maintenance/filters.py
+++ b/geotrek/maintenance/filters.py
@@ -2,13 +2,14 @@
from django.conf import settings
from django.contrib.gis.geos import GeometryCollection
from django.utils.translation import gettext_lazy as _
-from django_filters import ChoiceFilter, MultipleChoiceFilter
+from django_filters import ChoiceFilter, MultipleChoiceFilter, DateFromToRangeFilter
from mapentity.filters import PolygonFilter, PythonPolygonFilter
from geotrek.altimetry.filters import AltimetryPointFilterSet
from geotrek.authent.filters import StructureRelatedFilterSet
from geotrek.common.filters import OptionalRangeFilter, RightFilter
+from geotrek.common.widgets import OneLineRangeWidget
from geotrek.zoning.filters import (IntersectionFilterCity, IntersectionFilterDistrict,
IntersectionFilterRestrictedArea, IntersectionFilterRestrictedAreaType,
ZoningFilterSet)
@@ -121,6 +122,13 @@ class AltimetryInterventionFilterSet(AltimetryPointFilterSet):
slope = OptionalRangeFilter(label=_('slope'))
+class CustomDateFromToRangeFilter(DateFromToRangeFilter):
+ def __init__(self, *args, **kwargs):
+ super(DateFromToRangeFilter, self).__init__(*args, **kwargs)
+ self.field.fields[0].label = _('min %s') % self.field.label
+ self.field.fields[1].label = _('max %s') % self.field.label
+
+
class InterventionFilterSet(AltimetryInterventionFilterSet, ZoningFilterSet, StructureRelatedFilterSet):
ON_CHOICES = (('infrastructure', _("Infrastructure")), ('signage', _("Signage")), ('blade', _("Blade")),
('topology', _("Path")), ('trek', _("Trek")), ('poi', _("POI")), ('service', _("Service")),
@@ -130,8 +138,8 @@ class InterventionFilterSet(AltimetryInterventionFilterSet, ZoningFilterSet, Str
ON_CHOICES += (('course', _("Outdoor Course")), ('site', _("Outdoor Site")),)
bbox = PolygonTopologyFilter(lookup_expr='intersects')
- year = MultipleChoiceFilter(choices=lambda: Intervention.objects.year_choices(),
- field_name='date', lookup_expr='year', label=_("Year"))
+ begin_date = CustomDateFromToRangeFilter(lookup_expr='icontains', widget=OneLineRangeWidget(attrs={'type': 'date', 'class': 'minmax-field', 'title': _('Filter by begin date range')},), label=_('begin date'))
+ end_date = CustomDateFromToRangeFilter(lookup_expr='icontains', widget=OneLineRangeWidget(attrs={'type': 'date', 'class': 'minmax-field', 'title': _('Filter by end date range')},), label=_('end date'))
on = ChoiceFilter(field_name='target_type__model', choices=ON_CHOICES, label=_("On"), empty_label=_("On"))
area_type = InterventionIntersectionFilterRestrictedAreaType(label=_('Restricted area type'), required=False,
lookup_expr='intersects')
@@ -148,7 +156,6 @@ class Meta(StructureRelatedFilterSet.Meta):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- self.form.fields['year'].choices = Intervention.objects.year_choices()
class ProjectFilterSet(StructureRelatedFilterSet):
diff --git a/geotrek/maintenance/forms.py b/geotrek/maintenance/forms.py
index e89f0d5d9b..e8420dc2a8 100644
--- a/geotrek/maintenance/forms.py
+++ b/geotrek/maintenance/forms.py
@@ -74,7 +74,8 @@ class InterventionForm(CommonForm):
Div(
'structure',
'name',
- 'date',
+ 'begin_date',
+ 'end_date',
'status',
'disorders',
'type',
@@ -96,7 +97,7 @@ class InterventionForm(CommonForm):
class Meta(CommonForm.Meta):
model = Intervention
fields = CommonForm.Meta.fields + \
- ['structure', 'name', 'date', 'status', 'disorders', 'type', 'description', 'subcontracting', 'length', 'width',
+ ['structure', 'name', 'begin_date', 'end_date', 'status', 'disorders', 'type', 'description', 'subcontracting', 'length', 'width',
'height', 'stake', 'project', 'material_cost', 'heliport_cost', 'subcontract_cost', 'topology']
def __init__(self, *args, target_type=None, target_id=None, **kwargs):
diff --git a/geotrek/maintenance/locale/de/LC_MESSAGES/django.po b/geotrek/maintenance/locale/de/LC_MESSAGES/django.po
index 434260d4a0..b10bb88ad5 100644
--- a/geotrek/maintenance/locale/de/LC_MESSAGES/django.po
+++ b/geotrek/maintenance/locale/de/LC_MESSAGES/django.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2022-12-16 09:52+0000\n"
+"POT-Creation-Date: 2023-12-11 15:38+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
@@ -33,6 +33,14 @@ msgstr ""
msgid "slope"
msgstr ""
+#, python-format
+msgid "min %s"
+msgstr ""
+
+#, python-format
+msgid "max %s"
+msgstr ""
+
msgid "Infrastructure"
msgstr ""
@@ -63,7 +71,16 @@ msgstr ""
msgid "Outdoor Site"
msgstr ""
-msgid "Year"
+msgid "Filter by begin date range"
+msgstr ""
+
+msgid "begin date"
+msgstr ""
+
+msgid "Filter by end date range"
+msgstr ""
+
+msgid "end date"
msgstr ""
msgid "On"
@@ -117,6 +134,12 @@ msgstr ""
msgid "When ?"
msgstr ""
+msgid "Begin date"
+msgstr ""
+
+msgid "End date"
+msgstr ""
+
msgid "Subcontracting"
msgstr ""
diff --git a/geotrek/maintenance/locale/en/LC_MESSAGES/django.po b/geotrek/maintenance/locale/en/LC_MESSAGES/django.po
index 434260d4a0..b10bb88ad5 100644
--- a/geotrek/maintenance/locale/en/LC_MESSAGES/django.po
+++ b/geotrek/maintenance/locale/en/LC_MESSAGES/django.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2022-12-16 09:52+0000\n"
+"POT-Creation-Date: 2023-12-11 15:38+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
@@ -33,6 +33,14 @@ msgstr ""
msgid "slope"
msgstr ""
+#, python-format
+msgid "min %s"
+msgstr ""
+
+#, python-format
+msgid "max %s"
+msgstr ""
+
msgid "Infrastructure"
msgstr ""
@@ -63,7 +71,16 @@ msgstr ""
msgid "Outdoor Site"
msgstr ""
-msgid "Year"
+msgid "Filter by begin date range"
+msgstr ""
+
+msgid "begin date"
+msgstr ""
+
+msgid "Filter by end date range"
+msgstr ""
+
+msgid "end date"
msgstr ""
msgid "On"
@@ -117,6 +134,12 @@ msgstr ""
msgid "When ?"
msgstr ""
+msgid "Begin date"
+msgstr ""
+
+msgid "End date"
+msgstr ""
+
msgid "Subcontracting"
msgstr ""
diff --git a/geotrek/maintenance/locale/es/LC_MESSAGES/django.po b/geotrek/maintenance/locale/es/LC_MESSAGES/django.po
index 434260d4a0..b10bb88ad5 100644
--- a/geotrek/maintenance/locale/es/LC_MESSAGES/django.po
+++ b/geotrek/maintenance/locale/es/LC_MESSAGES/django.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2022-12-16 09:52+0000\n"
+"POT-Creation-Date: 2023-12-11 15:38+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
@@ -33,6 +33,14 @@ msgstr ""
msgid "slope"
msgstr ""
+#, python-format
+msgid "min %s"
+msgstr ""
+
+#, python-format
+msgid "max %s"
+msgstr ""
+
msgid "Infrastructure"
msgstr ""
@@ -63,7 +71,16 @@ msgstr ""
msgid "Outdoor Site"
msgstr ""
-msgid "Year"
+msgid "Filter by begin date range"
+msgstr ""
+
+msgid "begin date"
+msgstr ""
+
+msgid "Filter by end date range"
+msgstr ""
+
+msgid "end date"
msgstr ""
msgid "On"
@@ -117,6 +134,12 @@ msgstr ""
msgid "When ?"
msgstr ""
+msgid "Begin date"
+msgstr ""
+
+msgid "End date"
+msgstr ""
+
msgid "Subcontracting"
msgstr ""
diff --git a/geotrek/maintenance/locale/fr/LC_MESSAGES/django.po b/geotrek/maintenance/locale/fr/LC_MESSAGES/django.po
index fc56a703a6..bbedb09c31 100644
--- a/geotrek/maintenance/locale/fr/LC_MESSAGES/django.po
+++ b/geotrek/maintenance/locale/fr/LC_MESSAGES/django.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2022-12-16 09:52+0000\n"
+"POT-Creation-Date: 2023-12-11 15:38+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
@@ -32,6 +32,14 @@ msgstr ""
msgid "slope"
msgstr ""
+#, python-format
+msgid "min %s"
+msgstr ""
+
+#, python-format
+msgid "max %s"
+msgstr ""
+
msgid "Infrastructure"
msgstr "Aménagement"
@@ -62,8 +70,17 @@ msgstr "Parcours Outdoor"
msgid "Outdoor Site"
msgstr "Site Outdoor"
-msgid "Year"
-msgstr "Année"
+msgid "Filter by begin date range"
+msgstr "Filtrer par intervalle de date de début"
+
+msgid "begin date"
+msgstr "date de début"
+
+msgid "Filter by end date range"
+msgstr "Filtrer par intervalle de date de fin"
+
+msgid "end date"
+msgstr "date de fin"
msgid "On"
msgstr "Sur"
@@ -116,6 +133,12 @@ msgstr "Date"
msgid "When ?"
msgstr "Quand ?"
+msgid "Begin date"
+msgstr "Date de début"
+
+msgid "End date"
+msgstr "Date de fin"
+
msgid "Subcontracting"
msgstr "Sous-traitance"
@@ -347,6 +370,3 @@ msgstr "Ajouter un financement"
msgid "No intervention related."
msgstr "Pas d'intervention liée."
-
-msgid "Start year is after end year"
-msgstr "L'année de début est après l'année de fin"
diff --git a/geotrek/maintenance/locale/it/LC_MESSAGES/django.po b/geotrek/maintenance/locale/it/LC_MESSAGES/django.po
index 434260d4a0..b10bb88ad5 100644
--- a/geotrek/maintenance/locale/it/LC_MESSAGES/django.po
+++ b/geotrek/maintenance/locale/it/LC_MESSAGES/django.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2022-12-16 09:52+0000\n"
+"POT-Creation-Date: 2023-12-11 15:38+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
@@ -33,6 +33,14 @@ msgstr ""
msgid "slope"
msgstr ""
+#, python-format
+msgid "min %s"
+msgstr ""
+
+#, python-format
+msgid "max %s"
+msgstr ""
+
msgid "Infrastructure"
msgstr ""
@@ -63,7 +71,16 @@ msgstr ""
msgid "Outdoor Site"
msgstr ""
-msgid "Year"
+msgid "Filter by begin date range"
+msgstr ""
+
+msgid "begin date"
+msgstr ""
+
+msgid "Filter by end date range"
+msgstr ""
+
+msgid "end date"
msgstr ""
msgid "On"
@@ -117,6 +134,12 @@ msgstr ""
msgid "When ?"
msgstr ""
+msgid "Begin date"
+msgstr ""
+
+msgid "End date"
+msgstr ""
+
msgid "Subcontracting"
msgstr ""
diff --git a/geotrek/maintenance/locale/nl/LC_MESSAGES/django.po b/geotrek/maintenance/locale/nl/LC_MESSAGES/django.po
index 434260d4a0..b10bb88ad5 100644
--- a/geotrek/maintenance/locale/nl/LC_MESSAGES/django.po
+++ b/geotrek/maintenance/locale/nl/LC_MESSAGES/django.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2022-12-16 09:52+0000\n"
+"POT-Creation-Date: 2023-12-11 15:38+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
@@ -33,6 +33,14 @@ msgstr ""
msgid "slope"
msgstr ""
+#, python-format
+msgid "min %s"
+msgstr ""
+
+#, python-format
+msgid "max %s"
+msgstr ""
+
msgid "Infrastructure"
msgstr ""
@@ -63,7 +71,16 @@ msgstr ""
msgid "Outdoor Site"
msgstr ""
-msgid "Year"
+msgid "Filter by begin date range"
+msgstr ""
+
+msgid "begin date"
+msgstr ""
+
+msgid "Filter by end date range"
+msgstr ""
+
+msgid "end date"
msgstr ""
msgid "On"
@@ -117,6 +134,12 @@ msgstr ""
msgid "When ?"
msgstr ""
+msgid "Begin date"
+msgstr ""
+
+msgid "End date"
+msgstr ""
+
msgid "Subcontracting"
msgstr ""
diff --git a/geotrek/maintenance/managers.py b/geotrek/maintenance/managers.py
index 2132bae747..808ef8f73d 100644
--- a/geotrek/maintenance/managers.py
+++ b/geotrek/maintenance/managers.py
@@ -6,7 +6,7 @@
class InterventionManager(NoDeleteManager):
def year_choices(self):
- values = self.existing().filter(date__isnull=False).annotate(year=ExtractYear('date')) \
+ values = self.existing().filter(begin_date__isnull=False).annotate(year=ExtractYear('begin_date')) \
.order_by('-year').distinct().values_list('year', flat=True)
return [(year, year) for year in values]
diff --git a/geotrek/maintenance/migrations/0023_auto_20231206_1627.py b/geotrek/maintenance/migrations/0023_auto_20231206_1627.py
new file mode 100644
index 0000000000..8b8861758a
--- /dev/null
+++ b/geotrek/maintenance/migrations/0023_auto_20231206_1627.py
@@ -0,0 +1,34 @@
+# Generated by Django 3.2.21 on 2023-12-06 16:27
+
+import datetime
+from django.db import migrations, models
+
+
+def copy_date_into_begin_date(apps, schema_editor):
+ # Get maintenance models to copy date filed into begin_date
+ Intervention = apps.get_model('maintenance', 'Intervention')
+
+ for inter in Intervention.objects.all():
+ inter.begin_date = inter.date
+ inter.save()
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('maintenance', '0022_auto_20230503_0837'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='intervention',
+ name='begin_date',
+ field=models.DateField(default=datetime.datetime.now, verbose_name='Begin date'),
+ ),
+ migrations.AddField(
+ model_name='intervention',
+ name='end_date',
+ field=models.DateField(blank=True, null=True, verbose_name='End date'),
+ ),
+ migrations.RunPython(copy_date_into_begin_date, reverse_code=migrations.RunPython.noop),
+ ]
diff --git a/geotrek/maintenance/migrations/0024_remove_intervention_date.py b/geotrek/maintenance/migrations/0024_remove_intervention_date.py
new file mode 100644
index 0000000000..f3f5877f8d
--- /dev/null
+++ b/geotrek/maintenance/migrations/0024_remove_intervention_date.py
@@ -0,0 +1,17 @@
+# Generated by Django 3.2.21 on 2023-12-12 10:39
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('maintenance', '0023_auto_20231206_1627'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='intervention',
+ name='date',
+ ),
+ ]
diff --git a/geotrek/maintenance/models.py b/geotrek/maintenance/models.py
index 4d5b8d58ac..8eabf7ce1b 100755
--- a/geotrek/maintenance/models.py
+++ b/geotrek/maintenance/models.py
@@ -37,7 +37,8 @@ class Intervention(ZoningPropertiesMixin, AddPropertyMixin, GeotrekMapEntityMixi
target = GenericForeignKey('target_type', 'target_id')
name = models.CharField(verbose_name=_("Name"), max_length=128, help_text=_("Brief summary"))
- date = models.DateField(default=datetime.now, verbose_name=_("Date"), help_text=_("When ?"))
+ begin_date = models.DateField(default=datetime.now, blank=False, null=False, verbose_name=_("Begin date"))
+ end_date = models.DateField(blank=True, null=True, verbose_name=_("End date"))
subcontracting = models.BooleanField(verbose_name=_("Subcontracting"), default=False)
# Technical information
@@ -257,7 +258,7 @@ def name_csv_display(self):
return self.name
def __str__(self):
- return "%s (%s)" % (self.name, self.date)
+ return "%s (%s)" % (self.name, self.begin_date)
@classmethod
def get_interventions(cls, obj):
diff --git a/geotrek/maintenance/templates/maintenance/intervention_detail.html b/geotrek/maintenance/templates/maintenance/intervention_detail.html
index dd17121092..ce62cb117b 100644
--- a/geotrek/maintenance/templates/maintenance/intervention_detail.html
+++ b/geotrek/maintenance/templates/maintenance/intervention_detail.html
@@ -8,8 +8,12 @@
{{ intervention.name }} |
- {{ intervention|verbose:"date" }} |
- {{ intervention.date }} |
+ {{ intervention|verbose:"begin_date" }} |
+ {{ intervention.begin_date }} |
+
+
+ {{ intervention|verbose:"end_date" }} |
+ {{ intervention.end_date }} |
{{ intervention|verbose:"stake" }} |
diff --git a/geotrek/maintenance/templates/maintenance/maintenance_detail_fragment.html b/geotrek/maintenance/templates/maintenance/maintenance_detail_fragment.html
index a827084252..fc956cef68 100644
--- a/geotrek/maintenance/templates/maintenance/maintenance_detail_fragment.html
+++ b/geotrek/maintenance/templates/maintenance/maintenance_detail_fragment.html
@@ -7,7 +7,7 @@ {% trans "Works" %}
{% trans "Interventions" %}
- {% with columns="target,name,status,stake,total_cost,date" %}
+ {% with columns="target,name,status,stake,total_cost,begin_date,end_date" %}
{% if modelname == "project" %}
{% valuetable object.interventions.existing enumeration=True columns=columns %}
{% else %}
diff --git a/geotrek/maintenance/templates/maintenance/sql/post_20_views.sql b/geotrek/maintenance/templates/maintenance/sql/post_20_views.sql
index b73be9da5f..df87430bac 100644
--- a/geotrek/maintenance/templates/maintenance/sql/post_20_views.sql
+++ b/geotrek/maintenance/templates/maintenance/sql/post_20_views.sql
@@ -7,7 +7,8 @@ SELECT a.id,
f.zoning_city AS "City",
g.zoning_district AS "District",
a.name AS "Name",
- a.date AS "Date",
+ a.begin_date AS "Begin date",
+ a.end_date AS "End date",
d.stake AS "Stake",
c.status AS "Status",
b.type AS "Type",
diff --git a/geotrek/maintenance/templates/maintenance/sql/post_90_defaults.sql b/geotrek/maintenance/templates/maintenance/sql/post_90_defaults.sql
index ba9eca070b..6f676e3c03 100644
--- a/geotrek/maintenance/templates/maintenance/sql/post_90_defaults.sql
+++ b/geotrek/maintenance/templates/maintenance/sql/post_90_defaults.sql
@@ -1,7 +1,7 @@
-- Intervention
---------------
-- name
-ALTER TABLE maintenance_intervention ALTER COLUMN "date" SET DEFAULT now();
+ALTER TABLE maintenance_intervention ALTER COLUMN "begin_date" SET DEFAULT now();
ALTER TABLE maintenance_intervention ALTER COLUMN subcontracting SET DEFAULT FALSE;
ALTER TABLE maintenance_intervention ALTER COLUMN width SET DEFAULT 0.0;
ALTER TABLE maintenance_intervention ALTER COLUMN height SET DEFAULT 0.0;
diff --git a/geotrek/maintenance/tests/factories.py b/geotrek/maintenance/tests/factories.py
index 1e228a5197..9b70ccb743 100644
--- a/geotrek/maintenance/tests/factories.py
+++ b/geotrek/maintenance/tests/factories.py
@@ -59,7 +59,7 @@ class Meta:
class InterventionFactory(LightInterventionFactory):
- date = '2022-03-30'
+ begin_date = '2022-03-30'
@factory.post_generation
def create_intervention(obj, create, extracted, **kwargs):
diff --git a/geotrek/maintenance/tests/test_views.py b/geotrek/maintenance/tests/test_views.py
index 0005f3ec13..23c4de9c00 100644
--- a/geotrek/maintenance/tests/test_views.py
+++ b/geotrek/maintenance/tests/test_views.py
@@ -73,7 +73,8 @@ def get_good_data(self):
InterventionStatusFactory.create()
good_data = {
'name': 'test',
- 'date': '2012-08-23',
+ 'begin_date': '2012-08-23',
+ 'end_date': "",
'disorders': InterventionDisorderFactory.create().pk,
'comments': '',
'slope': 0,
@@ -111,7 +112,8 @@ def get_good_data(self):
def get_expected_datatables_attrs(self):
return {
- 'date': '30/03/2022',
+ 'begin_date': '30/03/2022',
+ 'end_date': None,
'id': self.obj.pk,
'name': self.obj.name_display,
'stake': self.obj.stake.stake,
@@ -253,6 +255,7 @@ def test_update_form_on_signage(self):
'manday_set-TOTAL_FORMS': '0',
'manday_set-INITIAL_FORMS': '0',
'manday_set-MAX_NUM_FORMS': '',
+ 'end_date': ''
})
# Form URL is modified in form init
formurl = '%s?target_id=%s&target_type=%s' % (intervention.get_update_url(), signa.pk, ContentType.objects.get_for_model(Signage).pk)
@@ -343,6 +346,7 @@ def test_update_form_on_infrastructure(self):
'manday_set-TOTAL_FORMS': '0',
'manday_set-INITIAL_FORMS': '0',
'manday_set-MAX_NUM_FORMS': '',
+ 'end_date': ''
})
# Form URL is modified in form init
formurl = '%s?target_id=%s&target_type=%s' % (Intervention.get_add_url(),
diff --git a/geotrek/maintenance/views.py b/geotrek/maintenance/views.py
index 0ba6b1a5c0..9adee721f5 100755
--- a/geotrek/maintenance/views.py
+++ b/geotrek/maintenance/views.py
@@ -35,7 +35,7 @@ class InterventionList(CustomColumnsMixin, MapEntityList):
queryset = Intervention.objects.existing()
filterform = InterventionFilterSet
mandatory_columns = ['id', 'name']
- default_extra_columns = ['date', 'type', 'target', 'status', 'stake']
+ default_extra_columns = ['begin_date', 'end_date', 'type', 'target', 'status', 'stake']
searchable_columns = ['id', 'name']
unorderable_columns = ['target']
@@ -97,7 +97,7 @@ def get_mandatory_columns(cls):
return mandatory_columns
default_extra_columns = [
- 'name', 'date', 'type', 'target', 'status', 'stake',
+ 'name', 'begin_date', 'end_date', 'type', 'target', 'status', 'stake',
'disorders', 'total_manday', 'project', 'subcontracting',
'width', 'height', 'area', 'structure',
'description', 'date_insert', 'date_update',
diff --git a/geotrek/signage/filters.py b/geotrek/signage/filters.py
index 26b4cb61ef..a7e73c0398 100644
--- a/geotrek/signage/filters.py
+++ b/geotrek/signage/filters.py
@@ -46,7 +46,7 @@ class Meta(StructureRelatedFilterSet.Meta):
def filter_intervention_year(self, qs, name, value):
signage_ct = ContentType.objects.get_for_model(Signage)
- interventions = Intervention.objects.filter(target_type=signage_ct, date__year__in=value) \
+ interventions = Intervention.objects.filter(target_type=signage_ct, begin_date__year__in=value) \
.values_list('target_id', flat=True)
return qs.filter(id__in=interventions).distinct()
| |