Skip to content

Commit

Permalink
Merge pull request #4982 from open-formulieren/issue/4969-map-tile-la…
Browse files Browse the repository at this point in the history
…yers-fixture

Load map tile layers fixture automatically
  • Loading branch information
sergei-maertens authored Jan 2, 2025
2 parents d136b35 + 4d9b8ea commit 31220c8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
7 changes: 6 additions & 1 deletion bin/generate_default_map_tile_layers_fixture.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
#
# Run this script from the root of the repository

src/manage.py dumpdata --indent=4 --natural-foreign --natural-primary config.MapTileLayer > src/openforms/fixtures/default_map_tile_layers.json
src/manage.py dumpdata \
--indent=4 \
--natural-foreign \
--natural-primary \
config.MapTileLayer \
> src/openforms/fixtures/default_map_tile_layers.json
10 changes: 10 additions & 0 deletions src/openforms/config/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
from io import StringIO

from django.apps import AppConfig
from django.core.management import call_command
from django.db.models.signals import post_migrate
from django.dispatch import receiver


class OpenFormsConfigConfig(AppConfig):
name = "openforms.config"
verbose_name = "Configuration"


@receiver(post_migrate, dispatch_uid="load_default_map_tile_layers")
def update_map_tile_layers(sender, **kwargs):
call_command("loaddata", "default_map_tile_layers", verbosity=0, stdout=StringIO())
12 changes: 12 additions & 0 deletions src/openforms/config/models/map.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from __future__ import annotations

from django.db import models
from django.utils.translation import gettext_lazy as _


class MapTileLayerManager(models.Manager["MapTileLayer"]):
def get_by_natural_key(self, identifier: str) -> MapTileLayer:
return self.get(identifier=identifier)


class MapTileLayer(models.Model):
identifier = models.SlugField(
_("identifier"),
Expand All @@ -27,10 +34,15 @@ class MapTileLayer(models.Model):
),
)

objects = MapTileLayerManager()

class Meta:
verbose_name = _("map tile layer")
verbose_name_plural = _("map tile layers")
ordering = ("label",)

def __str__(self):
return self.label

def natural_key(self):
return (self.identifier,)
2 changes: 0 additions & 2 deletions src/openforms/fixtures/default_map_tile_layers.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[
{
"model": "config.maptilelayer",
"pk": 1,
"fields": {
"identifier": "brt",
"url": "https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0/standaard/EPSG:28992/{z}/{x}/{y}.png",
Expand All @@ -10,7 +9,6 @@
},
{
"model": "config.maptilelayer",
"pk": 2,
"fields": {
"identifier": "luchtfoto",
"url": "https://service.pdok.nl/hwh/luchtfotorgb/wmts/v1_0/Actueel_orthoHR/EPSG:28992/{z}/{x}/{y}.png",
Expand Down

0 comments on commit 31220c8

Please sign in to comment.