Remove Map.tilelayer foreignkey
Map tilelayer is saved in the settings since a long time now.
This commit is contained in:
parent
96fa60e367
commit
72b943d779
5 changed files with 22 additions and 13 deletions
17
umap/migrations/0005_remove_map_tilelayer.py
Normal file
17
umap/migrations/0005_remove_map_tilelayer.py
Normal file
|
@ -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',
|
||||
),
|
||||
]
|
|
@ -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"))
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue