From 72b943d77936b38d502b359648184f0147bffe26 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sat, 14 Jul 2018 13:59:40 +0200 Subject: [PATCH] Remove Map.tilelayer foreignkey Map tilelayer is saved in the settings since a long time now. --- umap/migrations/0005_remove_map_tilelayer.py | 17 +++++++++++++++++ umap/models.py | 6 +++--- umap/templatetags/umap_tags.py | 3 +-- umap/tests/test_map.py | 1 - umap/views.py | 8 +------- 5 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 umap/migrations/0005_remove_map_tilelayer.py diff --git a/umap/migrations/0005_remove_map_tilelayer.py b/umap/migrations/0005_remove_map_tilelayer.py new file mode 100644 index 00000000..e6a57cbe --- /dev/null +++ b/umap/migrations/0005_remove_map_tilelayer.py @@ -0,0 +1,17 @@ +# Generated by Django 2.0.7 on 2018-07-14 11:58 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('umap', '0004_add_licence'), + ] + + operations = [ + migrations.RemoveField( + model_name='map', + name='tilelayer', + ), + ] diff --git a/umap/models.py b/umap/models.py index 0e7812b2..fddc0958 100644 --- a/umap/models.py +++ b/umap/models.py @@ -87,11 +87,12 @@ class TileLayer(NamedModel): return cls.objects.order_by('rank')[0] # FIXME, make it administrable @classmethod - def get_list(cls, selected=None): + def get_list(cls): + default = cls.get_default() l = [] for t in cls.objects.all(): fields = t.json - if selected and selected.pk == t.pk: + if default and default.pk == t.pk: fields['selected'] = True l.append(fields) return l @@ -133,7 +134,6 @@ class Map(NamedModel): default=get_default_licence ) modified_at = models.DateTimeField(auto_now=True) - tilelayer = models.ForeignKey(TileLayer, blank=True, null=True, related_name="maps", verbose_name=_("background"), on_delete=models.PROTECT) owner = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name="owned_maps", verbose_name=_("owner"), on_delete=models.PROTECT) editors = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True, verbose_name=_("editors")) edit_status = models.SmallIntegerField(choices=EDIT_STATUS, default=OWNER, verbose_name=_("edit status")) diff --git a/umap/templatetags/umap_tags.py b/umap/templatetags/umap_tags.py index be620533..d6be5091 100644 --- a/umap/templatetags/umap_tags.py +++ b/umap/templatetags/umap_tags.py @@ -29,12 +29,11 @@ def umap_js(locale=None): def map_fragment(map_instance, **kwargs): layers = DataLayer.objects.filter(map=map_instance) datalayer_data = [c.metadata for c in layers] - tilelayers = TileLayer.get_list() # TODO: no need to all map_settings = map_instance.settings if "properties" not in map_settings: map_settings['properties'] = {} map_settings['properties'].update({ - 'tilelayers': tilelayers, + 'tilelayers': [TileLayer.get_default().json], 'datalayers': datalayer_data, 'urls': _urls_for_js(), 'STATIC_URL': settings.STATIC_URL, diff --git a/umap/tests/test_map.py b/umap/tests/test_map.py index c72d3d1f..f54a8afa 100644 --- a/umap/tests/test_map.py +++ b/umap/tests/test_map.py @@ -68,7 +68,6 @@ def test_clone_should_return_new_instance(map, user): assert map.center == clone.center assert map.zoom == clone.zoom assert map.licence == clone.licence - assert map.tilelayer == clone.tilelayer def test_clone_should_keep_editors(map, user): diff --git a/umap/views.py b/umap/views.py index 62e4494f..3c91e54a 100644 --- a/umap/views.py +++ b/umap/views.py @@ -353,7 +353,7 @@ class MapDetailMixin: context = super(MapDetailMixin, self).get_context_data(**kwargs) properties = { 'urls': _urls_for_js(), - 'tilelayers': self.get_tilelayers(), + 'tilelayers': TileLayer.get_list(), 'allowEdit': self.is_edit_allowed(), 'default_iconUrl': "%sumap/img/marker.png" % settings.STATIC_URL, # noqa 'umap_id': self.get_umap_id(), @@ -384,9 +384,6 @@ class MapDetailMixin: indent=settings.DEBUG) return context - def get_tilelayers(self): - return TileLayer.get_list(selected=TileLayer.get_default()) - def get_datalayers(self): return [] @@ -432,9 +429,6 @@ class MapView(MapDetailMixin, DetailView): datalayers = DataLayer.objects.filter(map=self.object) return [l.metadata for l in datalayers] - def get_tilelayers(self): - return TileLayer.get_list(selected=self.object.get_tilelayer()) - def is_edit_allowed(self): return self.object.can_edit(self.request.user, self.request)