From 3c32377c4245c2b2f22367ed974a37b07630ecdd Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sat, 26 Nov 2016 17:25:59 +0100 Subject: [PATCH] Add a migration to create a TileLayer if none exists --- docs/ubuntu.md | 11 ---------- umap/migrations/0001_add_tilelayer.py | 29 +++++++++++++++++++++++++++ umap/migrations/__init__.py | 0 3 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 umap/migrations/0001_add_tilelayer.py create mode 100644 umap/migrations/__init__.py diff --git a/docs/ubuntu.md b/docs/ubuntu.md index aeb3deb9..7bf6dad3 100644 --- a/docs/ubuntu.md +++ b/docs/ubuntu.md @@ -104,17 +104,6 @@ For example: - name: `ODbL` - URL: `http://opendatacommons.org/licenses/odbl/` -## Add at least one tilelayer - -Go to [http://localhost:8000/admin/leaflet_storage/tilelayer/add/](http://localhost:8000/admin/leaflet_storage/tilelayer/add/) and create -a new TileLayer object. - -For example: - -- name: `Positron` -- URL template: `https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png` -- attribution: `© [[http://www.openstreetmap.org/copyright|OpenStreetMap]] contributors, © [[https://carto.com/attributions|CARTO]]` - You can now go to [http://localhost:8000/](http://localhost:8000/) and try to create a map for testing. When you're done with testing, quit the demo server (type Ctrl-C). diff --git a/umap/migrations/0001_add_tilelayer.py b/umap/migrations/0001_add_tilelayer.py new file mode 100644 index 00000000..6f1281ad --- /dev/null +++ b/umap/migrations/0001_add_tilelayer.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2016-11-26 16:02 +from __future__ import unicode_literals + +from django.db import migrations + + +def add_tilelayer(apps, *args): + TileLayer = apps.get_model('leaflet_storage', 'TileLayer') + if TileLayer.objects.count(): + return + TileLayer( + name='Positron', + url_template=('https://cartodb-basemaps-{s}.global.ssl.fastly.net/' + 'light_all/{z}/{x}/{y}.png'), + attribution=('© [[http://www.openstreetmap.org/copyright|' + 'OpenStreetMap]] contributors, © ' + '[[https://carto.com/attributions|CARTO]]')).save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('leaflet_storage', '0001_initial'), + ] + + operations = [ + migrations.RunPython(add_tilelayer), + ] diff --git a/umap/migrations/__init__.py b/umap/migrations/__init__.py new file mode 100644 index 00000000..e69de29b