Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load map tile layers fixture automatically #4982

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading