maps: custom error message for missing map layer on import (#72543)

This commit is contained in:
Lauréline Guérin 2022-12-19 08:26:24 +01:00 committed by Gitea
parent 12b2c350be
commit 557aec457e
2 changed files with 14 additions and 1 deletions

View File

@ -32,6 +32,7 @@ from requests.models import PreparedRequest
from combo.data.library import register_cell_class
from combo.data.models import CellBase
from combo.data.utils import ImportSiteError
from combo.utils import get_templated_url, requests
KIND = [
@ -529,6 +530,12 @@ class Map(CellBase):
cell_data['layers'] = [
{'fields': {'map_layer': layer}, 'model': 'maps.maplayeroptions'} for layer in layers
]
for layer_options in cell_data.get('layers') or []:
maplayer_slug = layer_options['fields']['map_layer'][0]
try:
MapLayer.objects.get(slug=maplayer_slug)
except MapLayer.DoesNotExist:
raise ImportSiteError(_('Unknown map layer "%s"') % maplayer_slug)
return cell_data
def import_subobjects(self, cell_json):

View File

@ -22,7 +22,7 @@ from combo.apps.lingo.models import PaymentBackend, Regie
from combo.apps.maps.models import Map, MapLayer, MapLayerOptions
from combo.apps.pwa.models import PwaNavigationEntry, PwaSettings
from combo.data.models import LinkCell, Page, SiteSettings, TextCell
from combo.data.utils import MissingGroups, export_site, import_site
from combo.data.utils import ImportSiteError, MissingGroups, export_site, import_site
pytestmark = pytest.mark.django_db
@ -196,6 +196,12 @@ def test_import_export_map_cells(app, some_data, some_map_layers):
assert MapLayer.objects.filter(slug='foo').exists() is True
assert Map.objects.all()[0].layers.all()[0].slug == 'foo'
# test import with missing MapLayer
del site_data['map-layers']
MapLayer.objects.all().delete()
with pytest.raises(ImportSiteError, match='Unknown map layer "foo"'):
import_site(data=site_data, clean=True)
def test_group_restrictions_import_export(app, some_data):
group = Group(name='A Group')