Skip to content

Commit

Permalink
✨ [#2173] Add leaflet map admin configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmolen committed Nov 21, 2024
1 parent e4fb7bb commit d989289
Show file tree
Hide file tree
Showing 8 changed files with 376 additions and 159 deletions.
417 changes: 259 additions & 158 deletions src/openforms/conf/locale/nl/LC_MESSAGES/django.po

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion src/openforms/config/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@

from .admin_views import ThemePreviewView
from .forms import GlobalConfigurationAdminForm, ThemeAdminForm
from .models import CSPSetting, GlobalConfiguration, RichTextColor, Theme
from .models import (
CSPSetting,
GlobalConfiguration,
RichTextColor,
LeafletMapBackground,
Theme,
)


@admin.register(GlobalConfiguration)
Expand Down Expand Up @@ -98,6 +104,7 @@ class GlobalConfigurationAdmin(TranslationAdmin, SingletonModelAdmin):
"form_map_default_zoom_level",
"form_map_default_latitude",
"form_map_default_longitude",
"form_map_default_background",
),
)
},
Expand Down Expand Up @@ -217,6 +224,18 @@ class RichTextColorAdmin(admin.ModelAdmin):
]


@admin.register(LeafletMapBackground)
class LeafletMapBackgroundAdmin(admin.ModelAdmin):
fields = [
"label",
"url",
]
list_display = [
"label",
"url",
]


@admin.register(CSPSetting)
class CSPSettingAdmin(admin.ModelAdmin):
readonly_fields = ("content_type_link",)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Generated by Django 4.2.16 on 2024-11-21 10:12

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
(
"config",
"0066_alter_globalconfiguration_cosign_submission_confirmation_template_and_more",
),
]

operations = [
migrations.CreateModel(
name="LeafletMapBackground",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"url",
models.URLField(
help_text="URL to the Leaflet map background. Used for the form map components",
verbose_name="background url",
),
),
(
"label",
models.CharField(
help_text="An easily recognizable name for the background, used to identify it.",
max_length=100,
verbose_name="label",
),
),
],
options={
"verbose_name": "leaflet map background option",
"verbose_name_plural": "leaflet map background options",
"ordering": ("label",),
},
),
migrations.AddField(
model_name="globalconfiguration",
name="form_map_default_background",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="config.leafletmapbackground",
verbose_name="The default background for the leaflet map.",
),
),
]
2 changes: 2 additions & 0 deletions src/openforms/config/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from .color import RichTextColor
from .config import GlobalConfiguration
from .csp import CSPSetting
from .map import LeafletMapBackground
from .theme import Theme

__all__ = [
"CSPSetting",
"GlobalConfiguration",
"RichTextColor",
"LeafletMapBackground",
"Theme",
]
6 changes: 6 additions & 0 deletions src/openforms/config/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ class GlobalConfiguration(SingletonModel):
],
default=5.291266,
)
form_map_default_background = models.ForeignKey(
to="LeafletMapBackground",
on_delete=models.SET_NULL,
verbose_name=_("The default background for the leaflet map."),
null=True,
)
# 'subdomain' styling & content configuration
default_theme = models.OneToOneField(
Theme,
Expand Down
26 changes: 26 additions & 0 deletions src/openforms/config/models/map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.db import models
from django.utils.translation import gettext_lazy as _


class LeafletMapBackground(models.Model):
url = models.URLField(
_("background url"),
help_text=_(
"URL to the Leaflet map background. Used for the form map components"
),
)
label = models.CharField(
_("label"),
max_length=100,
help_text=_(
"An easily recognizable name for the background, used to identify it."
),
)

class Meta:
verbose_name = _("leaflet map background option")
verbose_name_plural = _("leaflet map background options")
ordering = ("label",)

def __str__(self):
return f"{self.label} ({self.url})"
1 change: 1 addition & 0 deletions src/openforms/fixtures/admin_index_unlisted.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
"config.RichTextColor",
"config.LeafletMapBackground",
"forms.FormLogic",
"forms.FormDefinition",
"forms.FormsExport",
Expand Down
1 change: 1 addition & 0 deletions src/openforms/formio/components/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def rewrite_for_request(component, request: Request):
component.setdefault("initialCenter", {})
component["initialCenter"]["lat"] = config.form_map_default_latitude
component["initialCenter"]["lng"] = config.form_map_default_longitude
component["background"] = config.form_map_default_background

def build_serializer_field(self, component: Component) -> serializers.ListField:
validate = component.get("validate", {})
Expand Down

0 comments on commit d989289

Please sign in to comment.