diff --git a/streetup/assets/locale/nl/LC_MESSAGES/django.mo b/streetup/assets/locale/nl/LC_MESSAGES/django.mo index be3b2f5..2aee0e2 100644 Binary files a/streetup/assets/locale/nl/LC_MESSAGES/django.mo and b/streetup/assets/locale/nl/LC_MESSAGES/django.mo differ diff --git a/streetup/assets/migrations/0019_naturerwiasset_location.py b/streetup/assets/migrations/0019_naturerwiasset_location.py new file mode 100644 index 0000000..826e9b1 --- /dev/null +++ b/streetup/assets/migrations/0019_naturerwiasset_location.py @@ -0,0 +1,29 @@ +# Generated by Django 6.0.7 on 2026-08-11 12:13 + +import django.db.models.deletion +from django.db import migrations, models + + +def populate_locations(apps, schema_editor): + NatureRWIZ = apps.get_model('assets', 'NatureRWIZ') + NatureRWIAsset = apps.get_model('assets', 'NatureRWIAsset') + + zones = NatureRWIZ.objects.filter(geom__isnull=False) + for zone in zones: + NatureRWIAsset.objects.filter(geom__intersects=zone.geom, location__isnull=True).update(location=zone) + + +class Migration(migrations.Migration): + + dependencies = [ + ('assets', '0018_remove_parkingspot_scooter_capacity'), + ] + + operations = [ + migrations.AddField( + model_name='naturerwiasset', + name='location', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assets', to='assets.naturerwiz', verbose_name='Zone GIEP / ZIEP'), + ), + migrations.RunPython(populate_locations, reverse_code=migrations.RunPython.noop), + ] diff --git a/streetup/assets/models/nature.py b/streetup/assets/models/nature.py index 5d2ef66..7968d07 100644 --- a/streetup/assets/models/nature.py +++ b/streetup/assets/models/nature.py @@ -277,14 +277,10 @@ class NatureRWIZ(AbstractLocation): geom = models.MultiPolygonField(srid=3812, null=True,blank=True) def get_active_assets(self): - if not self.geom: - return NatureRWIAsset.objects.none() - return NatureRWIAsset.objects.filter(geom__intersects=self.geom, status='active') + return NatureRWIAsset.objects.filter(location=self, status='active') def get_all_assets(self): - if not self.geom: - return NatureRWIAsset.objects.none() - return NatureRWIAsset.objects.filter(geom__intersects=self.geom) + return NatureRWIAsset.objects.filter(location=self) def get_absolute_url(self): return reverse( @@ -451,6 +447,7 @@ GEOMETRY_TYPE_CHOICES = [ class NatureRWIAsset(AbstractGeoAsset): + location = models.ForeignKey(NatureRWIZ, on_delete=models.SET_NULL, null=True, blank=True, related_name="assets", verbose_name=_("Zone GIEP / ZIEP")) geom = models.GeometryField(srid=3812, null=True, blank=True) external_id = models.IntegerField(null=True, blank=True, verbose_name=_("External ID")) @@ -485,6 +482,16 @@ class NatureRWIAsset(AbstractGeoAsset): verbose_name = _("RWI Asset") verbose_name_plural = _("RWI Assets") + def save(self, *args, **kwargs): + if not self.location_id and self.geom: + try: + matching_rwiz = NatureRWIZ.objects.filter(geom__intersects=self.geom).first() + if matching_rwiz: + self.location = matching_rwiz + except Exception: + pass + super().save(*args, **kwargs) + def get_absolute_url(self): return reverse('assets:water_assets_detail', kwargs={'asset_model': 'naturerwiasset', 'asset_id': self.id}) diff --git a/streetup/assets/permissions.py b/streetup/assets/permissions.py index 42f2376..382f27b 100644 --- a/streetup/assets/permissions.py +++ b/streetup/assets/permissions.py @@ -298,6 +298,7 @@ def _get_asset_thematic(asset): # Fallback: deduce thematic from asset class name class_name = asset.__class__.__name__.lower() thematic_mappings = { + 'naturerwiz': 'water', 'naturerwiasset': 'water', 'trafficlight': 'trafficlights', 'publiclighting': 'publiclighting', diff --git a/streetup/assets/templates/assets/components/asset_inspections.html b/streetup/assets/templates/assets/components/asset_inspections.html index 8c00ff2..91c4d8d 100644 --- a/streetup/assets/templates/assets/components/asset_inspections.html +++ b/streetup/assets/templates/assets/components/asset_inspections.html @@ -18,8 +18,8 @@ data-object-id="{{ asset_pk }}" data-target-code="{{ asset.code|default:asset.pk }}" data-target-name="{{ asset.name_fr|default:asset.name_nl|default:asset }}" - data-target-type="{{ asset.category.name_fr|default:'Asset' }}" - data-target-status="{{ asset.get_status_display|default:asset.inspection_status|default:'-' }}"> + data-target-type="{% if asset.category %}{{ asset.category.name_fr }}{% else %}{% translate 'Zone / Équipement' %}{% endif %}" + data-target-status="{% if asset.get_status_display %}{{ asset.get_status_display }}{% else %}-{% endif %}"> {% translate "Nouvelle inspection" %} {% endif %} @@ -86,7 +86,7 @@