From d88f57f867dbaa7751e1dca58c666ebebc7adabd Mon Sep 17 00:00:00 2001 From: nesnoj Date: Tue, 26 Nov 2024 10:39:17 +0100 Subject: [PATCH] Add popups for wind potential areas 2018 and 2024 --- config/settings/base.py | 8 +++ ...awindstp2024vr_municipality_id_and_more.py | 24 ++++++++ ...lter_potentialareawindstp2024vr_options.py | 17 ++++++ ...ty_id_potentialareawindstp2024vr_mun_id.py | 18 ++++++ ...lter_potentialareawindstp2024vr_options.py | 17 ++++++ ...ntialareawindstp2018eg_options_and_more.py | 28 +++++++++ .../0062_potentialareawindstp2018eg_weg_nr.py | 18 ++++++ digiplan/map/models.py | 28 +++++++++ digiplan/map/popups.py | 57 +++++++++++++++++++ 9 files changed, 215 insertions(+) create mode 100644 digiplan/map/migrations/0057_potentialareawindstp2024vr_municipality_id_and_more.py create mode 100644 digiplan/map/migrations/0058_alter_potentialareawindstp2024vr_options.py create mode 100644 digiplan/map/migrations/0059_rename_municipality_id_potentialareawindstp2024vr_mun_id.py create mode 100644 digiplan/map/migrations/0060_alter_potentialareawindstp2024vr_options.py create mode 100644 digiplan/map/migrations/0061_alter_potentialareawindstp2018eg_options_and_more.py create mode 100644 digiplan/map/migrations/0062_potentialareawindstp2018eg_weg_nr.py diff --git a/config/settings/base.py b/config/settings/base.py index 3ca998b0..8cbc7edb 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -601,6 +601,14 @@ def __getitem__(self, item): # noqa: D105, ANN001, ANN204 f"rpg_ols_pv_ground_planned{'_distilled' if DISTILL else ''}", popup_at_default_layer=True, ), + setup.Popup( + f"potentialarea_wind_stp_2018_eg{'_distilled' if DISTILL else ''}", + popup_at_default_layer=True, + ), + setup.Popup( + f"potentialarea_wind_stp_2024_vr{'_distilled' if DISTILL else ''}", + popup_at_default_layer=True, + ), setup.Popup( "pvground", popup_at_default_layer=True, diff --git a/digiplan/map/migrations/0057_potentialareawindstp2024vr_municipality_id_and_more.py b/digiplan/map/migrations/0057_potentialareawindstp2024vr_municipality_id_and_more.py new file mode 100644 index 00000000..31c98f2a --- /dev/null +++ b/digiplan/map/migrations/0057_potentialareawindstp2024vr_municipality_id_and_more.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.16 on 2024-11-26 08:22 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('map', '0056_alter_waterfirstorder_geom'), + ] + + operations = [ + migrations.AddField( + model_name='potentialareawindstp2024vr', + name='municipality_id', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='map.municipality'), + ), + migrations.AddField( + model_name='potentialareawindstp2024vr', + name='vr_wen_nr', + field=models.CharField(max_length=255, null=True), + ), + ] diff --git a/digiplan/map/migrations/0058_alter_potentialareawindstp2024vr_options.py b/digiplan/map/migrations/0058_alter_potentialareawindstp2024vr_options.py new file mode 100644 index 00000000..210979c7 --- /dev/null +++ b/digiplan/map/migrations/0058_alter_potentialareawindstp2024vr_options.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.16 on 2024-11-26 08:43 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('map', '0057_potentialareawindstp2024vr_municipality_id_and_more'), + ] + + operations = [ + migrations.AlterModelOptions( + name='potentialareawindstp2024vr', + options={'verbose_name': 'Vorranggebiet 1. Entwurf 2024', 'verbose_name_plural': 'Vorranggebiete 1. Entwurf 2024'}, + ), + ] diff --git a/digiplan/map/migrations/0059_rename_municipality_id_potentialareawindstp2024vr_mun_id.py b/digiplan/map/migrations/0059_rename_municipality_id_potentialareawindstp2024vr_mun_id.py new file mode 100644 index 00000000..b6c98787 --- /dev/null +++ b/digiplan/map/migrations/0059_rename_municipality_id_potentialareawindstp2024vr_mun_id.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.16 on 2024-11-26 08:53 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('map', '0058_alter_potentialareawindstp2024vr_options'), + ] + + operations = [ + migrations.RenameField( + model_name='potentialareawindstp2024vr', + old_name='municipality_id', + new_name='mun_id', + ), + ] diff --git a/digiplan/map/migrations/0060_alter_potentialareawindstp2024vr_options.py b/digiplan/map/migrations/0060_alter_potentialareawindstp2024vr_options.py new file mode 100644 index 00000000..4e0c89e5 --- /dev/null +++ b/digiplan/map/migrations/0060_alter_potentialareawindstp2024vr_options.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.16 on 2024-11-26 08:57 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('map', '0059_rename_municipality_id_potentialareawindstp2024vr_mun_id'), + ] + + operations = [ + migrations.AlterModelOptions( + name='potentialareawindstp2024vr', + options={'verbose_name': 'Windvorranggebiet 1. Entwurf 2024', 'verbose_name_plural': 'Windvorranggebiete 1. Entwurf 2024'}, + ), + ] diff --git a/digiplan/map/migrations/0061_alter_potentialareawindstp2018eg_options_and_more.py b/digiplan/map/migrations/0061_alter_potentialareawindstp2018eg_options_and_more.py new file mode 100644 index 00000000..384b6295 --- /dev/null +++ b/digiplan/map/migrations/0061_alter_potentialareawindstp2018eg_options_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.16 on 2024-11-26 09:11 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('map', '0060_alter_potentialareawindstp2024vr_options'), + ] + + operations = [ + migrations.AlterModelOptions( + name='potentialareawindstp2018eg', + options={'verbose_name': 'Windeignungsgebiet 2018', 'verbose_name_plural': 'Windeignungsgebiete 2018'}, + ), + migrations.AddField( + model_name='potentialareawindstp2018eg', + name='mun_id', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='map.municipality'), + ), + migrations.AddField( + model_name='potentialareawindstp2018eg', + name='weg_name', + field=models.CharField(max_length=255, null=True), + ), + ] diff --git a/digiplan/map/migrations/0062_potentialareawindstp2018eg_weg_nr.py b/digiplan/map/migrations/0062_potentialareawindstp2018eg_weg_nr.py new file mode 100644 index 00000000..109a4565 --- /dev/null +++ b/digiplan/map/migrations/0062_potentialareawindstp2018eg_weg_nr.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.16 on 2024-11-26 09:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('map', '0061_alter_potentialareawindstp2018eg_options_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='potentialareawindstp2018eg', + name='weg_nr', + field=models.IntegerField(null=True), + ), + ] diff --git a/digiplan/map/models.py b/digiplan/map/models.py index 7bdea87e..4d9cc9da 100644 --- a/digiplan/map/models.py +++ b/digiplan/map/models.py @@ -705,11 +705,39 @@ class PotentialAreaWindSTP2018EG(StaticRegionModel): # noqa: D101 data_file = "potentialarea_wind_stp_2018_eg" layer = "potentialarea_wind_stp_2018_eg" + weg_nr = models.IntegerField(null=True) + weg_name = models.CharField(max_length=255, null=True) + mun_id = models.ForeignKey(Municipality, on_delete=models.DO_NOTHING, null=True) + + mapping = { + "geom": "MULTIPOLYGON", + "weg_nr": "weg_nr", + "weg_name": "weg_name", + "mun_id": {"id": "municipality_id"}, + } + + class Meta: # noqa: D106 + verbose_name = _("Windeignungsgebiet 2018") + verbose_name_plural = _("Windeignungsgebiete 2018") + class PotentialAreaWindSTP2024VR(StaticRegionModel): # noqa: D101 data_file = "potentialarea_wind_stp_2024_vr" layer = "potentialarea_wind_stp_2024_vr" + vr_wen_nr = models.CharField(max_length=255, null=True) + mun_id = models.ForeignKey(Municipality, on_delete=models.DO_NOTHING, null=True) + + mapping = { + "geom": "MULTIPOLYGON", + "vr_wen_nr": "vr_wen_nr", + "mun_id": {"id": "municipality_id"}, + } + + class Meta: # noqa: D106 + verbose_name = _("Windvorranggebiet 1. Entwurf 2024") + verbose_name_plural = _("Windvorranggebiete 1. Entwurf 2024") + class PVgroundAreas(StaticRegionModel): """Model holding PV on ground (dataset by RPG with areas).""" diff --git a/digiplan/map/popups.py b/digiplan/map/popups.py index 0e181074..c747b2be 100644 --- a/digiplan/map/popups.py +++ b/digiplan/map/popups.py @@ -1030,6 +1030,61 @@ class WindTurbine2PlannedPopup(WindTurbine2ClusterPopup): description = _("Geplante Windenergieanlagen (Daten: RPG Oderland-Spree, Stand: 08.10.2024)") +class WindAreaPopup(popups.Popup): + """Wind area popup.""" + + description: str = None + + def __init__(self, lookup: str, selected_id: int, **kwargs) -> None: # noqa: ARG002 + """Initialize popup with table template.""" + self.model_lookup = lookup + super().__init__(lookup="base", selected_id=selected_id) + + def get_context_data(self) -> dict: + """Return cluster data as context data.""" + model = { + "potentialarea_wind_stp_2018_eg": models.PotentialAreaWindSTP2018EG, + "potentialarea_wind_stp_2024_vr": models.PotentialAreaWindSTP2024VR, + }[self.model_lookup] + default_attributes = {} + specific_attributes = { + "mun_id": "Gemeinde", + "weg_nr": "Nr. Eignungsgebiet", + "vr_wen_nr": "Name Vorranggebiet", + } + instance = model.objects.annotate(mun_name=F("mun_id")).get(pk=self.selected_id) + data_dict = { + "title": model._meta.verbose_name, # noqa: SLF001 + "description": self.description, + "data": {name: getattr(instance, key) for key, name in default_attributes.items()}, + } + + for key, name in specific_attributes.items(): + if hasattr(instance, key): + value = getattr(instance, key) + data_dict["data"][name] = value + + return data_dict + + +class PotentialAreaWindSTP2018EG(WindAreaPopup): + """Popup for planned wind turbines (dataset by RPG with areas).""" + + description = _( + "Windeignungsgebiet aus Sachlichem Teilregionalplan Windenergienutzung 2018. Daten: RPG Oderland-Spree", + ) + + +class PotentialAreaWindSTP2024VRPopup(WindAreaPopup): + """Popup for planned wind turbines (dataset by RPG with areas).""" + + description = _( + "Windvorranggebiet aus 1. Entwurf des Sachlichen Teilplans Erneuerbare Energien 2024 der Regionalen " + "Planungsgemeinschaft (nicht rechtskräftig). " + "Daten: RPG Oderland-Spree, Stand: Januar 2024", + ) + + POPUPS: dict[str, type(popups.Popup)] = { "wind": ClusterPopup, "pvroof": ClusterPopup, @@ -1075,4 +1130,6 @@ class WindTurbine2PlannedPopup(WindTurbine2ClusterPopup): "rpg_ols_wind_approved": WindTurbine2ApprovedPopup, "rpg_ols_wind_operating": WindTurbine2OperatingPopup, "rpg_ols_wind_planned": WindTurbine2PlannedPopup, + "potentialarea_wind_stp_2018_eg": PotentialAreaWindSTP2018EG, + "potentialarea_wind_stp_2024_vr": PotentialAreaWindSTP2024VRPopup, }