diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 940f597..cf5b33c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,24 +1,45 @@ CHANGELOG ========= +1.1.6 (unreleased) +------------------ + +* TODO + + +1.1.5 (2019-07-08) +------------------ + +* Fix missing 'on_delete' in migrations +* Fix import of 'six' + + +1.1.4 (2019-04-29) +------------------ + +* Fix unicode error in python 3 +* Fix for 'query' field not used in model for Django 1.11 +* Fix leaking the admin url when accessed without login +* Add 'on_delete=models.CASCADE' required for Django 2.0 + 1.1.3 (2016-10-11) ------------------ -* fix unicode error in location plugin -* fix error introduced in 1.1.2 (commit f76dedd7) +* Fix unicode error in location plugin +* Fix error introduced in 1.1.2 (commit f76dedd7) 1.1.2 (2016-10-11) ------------------ -* path location plugin: fix absolute url +* Path location plugin: fix absolute url 1.1.1 (2016-09-14) ------------------ -* fix staticmap with new kml location plugin +* Fix staticmap with new kml location plugin 1.1.0 (2016-09-14) diff --git a/aldryn_locations/__init__.py b/aldryn_locations/__init__.py index 7bb021e..99d2a6f 100644 --- a/aldryn_locations/__init__.py +++ b/aldryn_locations/__init__.py @@ -1 +1 @@ -__version__ = '1.1.3' +__version__ = '1.1.5' diff --git a/aldryn_locations/cms_plugins.py b/aldryn_locations/cms_plugins.py index e5d3e4f..157114a 100644 --- a/aldryn_locations/cms_plugins.py +++ b/aldryn_locations/cms_plugins.py @@ -1,7 +1,7 @@ import json from django.utils.translation import ugettext_lazy as _ -from django.core.urlresolvers import reverse +from django.urls import reverse from cms.plugin_base import CMSPluginBase from cms.plugin_pool import plugin_pool @@ -56,6 +56,12 @@ def render(self, context, instance, placeholder): data = '{}{}'.format(base_url, data) path_sources.append(data) else: + if not request.toolbar or not ( + getattr(request.toolbar, 'edit_mode') + or getattr(request.toolbar, 'edit_mode_active') + ): + # do not leak /admin urls + data['admin'] = None location_data.append(data) # Options for the map comes from plugin so I assigned it here diff --git a/aldryn_locations/forms.py b/aldryn_locations/forms.py index 7c7d44f..5958f1b 100644 --- a/aldryn_locations/forms.py +++ b/aldryn_locations/forms.py @@ -66,7 +66,6 @@ class EmbedViewPluginForm(ModelForm): class Meta: model = EmbedViewPlugin fields = [ - 'query', 'map_type', 'center', 'zoom', diff --git a/aldryn_locations/migrations/0001_initial.py b/aldryn_locations/migrations/0001_initial.py index 660d82e..bd52bb9 100644 --- a/aldryn_locations/migrations/0001_initial.py +++ b/aldryn_locations/migrations/0001_initial.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from django.db import migrations, models +import django.db.models.deletion class Migration(migrations.Migration): @@ -14,21 +15,21 @@ class Migration(migrations.Migration): migrations.CreateModel( name='EmbedDirectionsPlugin', fields=[ - ('cmsplugin_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')), + ('cmsplugin_ptr', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')), ('query', models.CharField(help_text='defines the place to highlight on the map. It accepts a location as either a place name or address', max_length=255, verbose_name='Query')), - ('map_type', models.CharField(default=b'roadmap', max_length=300, verbose_name='Map Type', choices=[(b'roadmap', 'Roadmap'), (b'satellite', 'Satellite')])), + ('map_type', models.CharField(default='roadmap', max_length=300, verbose_name='Map Type', choices=[('roadmap', 'Roadmap'), ('satellite', 'Satellite')])), ('center', models.CharField(help_text='optionally define the center of the map view. It accepts a comma-separated latitude and longitude value (such as 37.4218,-122.0840).', max_length=255, null=True, verbose_name='Center of the map (latitude + longitude)', blank=True)), - ('zoom', models.CharField(choices=[(b'0', b'0'), (b'1', b'1'), (b'2', b'2'), (b'3', b'3'), (b'4', b'4'), (b'5', b'5'), (b'6', b'6'), (b'7', b'7'), (b'8', b'8'), (b'9', b'9'), (b'10', b'10'), (b'11', b'11'), (b'12', b'12'), (b'13', b'13'), (b'14', b'14'), (b'15', b'15'), (b'16', b'16'), (b'17', b'17'), (b'18', b'18'), (b'19', b'19'), (b'20', b'20'), (b'21', b'21')], max_length=2, blank=True, help_text='0 (the whole world) to 21 (individual buildings). Leave empty for auto zoom', null=True, verbose_name='Zoom level')), + ('zoom', models.CharField(choices=[('0', '0'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11'), ('12', '12'), ('13', '13'), ('14', '14'), ('15', '15'), ('16', '16'), ('17', '17'), ('18', '18'), ('19', '19'), ('20', '20'), ('21', '21')], max_length=2, blank=True, help_text='0 (the whole world) to 21 (individual buildings). Leave empty for auto zoom', null=True, verbose_name='Zoom level')), ('ui_lang', models.CharField(help_text='default to page language', max_length=10, null=True, verbose_name='language for ui elements', blank=True)), ('region', models.CharField(help_text=' defines the appropriate borders and labels to display, based on geo-political sensitivities. Accepts a region code specified as a two-character ccTLD (top-level domain) value.', max_length=10, null=True, verbose_name='map region (ccTLD)', blank=True)), - ('width', models.CharField(default=b'100%', help_text='Plugin width (in pixels or percent).', max_length=6, verbose_name='width')), - ('height', models.CharField(default=b'400px', help_text='Plugin height (in pixels).', max_length=6, verbose_name='height')), + ('width', models.CharField(default='100%', help_text='Plugin width (in pixels or percent).', max_length=6, verbose_name='width')), + ('height', models.CharField(default='400px', help_text='Plugin height (in pixels).', max_length=6, verbose_name='height')), ('origin', models.CharField(help_text='defines the origin and accepts a location as either a place name or address', max_length=255, verbose_name='origin')), ('destination', models.CharField(help_text='defines the destination and accepts a location as either a place name or address', max_length=255, verbose_name='destination')), ('waypoints', models.CharField(help_text='separated by the pipe character (|) (e.g. Berlin,Germany|Paris,France)', max_length=255, null=True, verbose_name='list of waypoints', blank=True)), - ('travel_mode', models.CharField(default=b'auto', max_length=50, verbose_name='travel mode', choices=[(b'auto', 'Automatic'), (b'driving', 'Driving'), (b'walking', 'Walking'), (b'bicycling', 'Bicycling'), (b'transit', 'Transit'), (b'flying', 'Flying')])), - ('avoid', models.CharField(blank=True, max_length=50, null=True, verbose_name='avoid certain means', choices=[(b'tolls', 'Tolls'), (b'highways', 'Highways'), (b'ferries', 'Ferries'), (b'tolls|highways', 'Tolls & Highways'), (b'tolls|ferries', 'Tolls & Ferries'), (b'ferries|highways', 'Ferries & Highways'), (b'tolls|ferries|highways', 'Tolls, Ferries & Highways')])), - ('units', models.CharField(default=b'auto', max_length=10, verbose_name='units for distances in results', choices=[(b'auto', 'Automatic'), (b'metric', 'Metric'), (b'imperial', 'Imperial')])), + ('travel_mode', models.CharField(default='auto', max_length=50, verbose_name='travel mode', choices=[('auto', 'Automatic'), ('driving', 'Driving'), ('walking', 'Walking'), ('bicycling', 'Bicycling'), ('transit', 'Transit'), ('flying', 'Flying')])), + ('avoid', models.CharField(blank=True, max_length=50, null=True, verbose_name='avoid certain means', choices=[('tolls', 'Tolls'), ('highways', 'Highways'), ('ferries', 'Ferries'), ('tolls|highways', 'Tolls & Highways'), ('tolls|ferries', 'Tolls & Ferries'), ('ferries|highways', 'Ferries & Highways'), ('tolls|ferries|highways', 'Tolls, Ferries & Highways')])), + ('units', models.CharField(default='auto', max_length=10, verbose_name='units for distances in results', choices=[('auto', 'Automatic'), ('metric', 'Metric'), ('imperial', 'Imperial')])), ], options={ 'abstract': False, @@ -38,15 +39,15 @@ class Migration(migrations.Migration): migrations.CreateModel( name='EmbedPlacePlugin', fields=[ - ('cmsplugin_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')), + ('cmsplugin_ptr', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')), ('query', models.CharField(help_text='defines the place to highlight on the map. It accepts a location as either a place name or address', max_length=255, verbose_name='Query')), - ('map_type', models.CharField(default=b'roadmap', max_length=300, verbose_name='Map Type', choices=[(b'roadmap', 'Roadmap'), (b'satellite', 'Satellite')])), + ('map_type', models.CharField(default='roadmap', max_length=300, verbose_name='Map Type', choices=[('roadmap', 'Roadmap'), ('satellite', 'Satellite')])), ('center', models.CharField(help_text='optionally define the center of the map view. It accepts a comma-separated latitude and longitude value (such as 37.4218,-122.0840).', max_length=255, null=True, verbose_name='Center of the map (latitude + longitude)', blank=True)), - ('zoom', models.CharField(choices=[(b'0', b'0'), (b'1', b'1'), (b'2', b'2'), (b'3', b'3'), (b'4', b'4'), (b'5', b'5'), (b'6', b'6'), (b'7', b'7'), (b'8', b'8'), (b'9', b'9'), (b'10', b'10'), (b'11', b'11'), (b'12', b'12'), (b'13', b'13'), (b'14', b'14'), (b'15', b'15'), (b'16', b'16'), (b'17', b'17'), (b'18', b'18'), (b'19', b'19'), (b'20', b'20'), (b'21', b'21')], max_length=2, blank=True, help_text='0 (the whole world) to 21 (individual buildings). Leave empty for auto zoom', null=True, verbose_name='Zoom level')), + ('zoom', models.CharField(choices=[('0', '0'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11'), ('12', '12'), ('13', '13'), ('14', '14'), ('15', '15'), ('16', '16'), ('17', '17'), ('18', '18'), ('19', '19'), ('20', '20'), ('21', '21')], max_length=2, blank=True, help_text='0 (the whole world) to 21 (individual buildings). Leave empty for auto zoom', null=True, verbose_name='Zoom level')), ('ui_lang', models.CharField(help_text='default to page language', max_length=10, null=True, verbose_name='language for ui elements', blank=True)), ('region', models.CharField(help_text=' defines the appropriate borders and labels to display, based on geo-political sensitivities. Accepts a region code specified as a two-character ccTLD (top-level domain) value.', max_length=10, null=True, verbose_name='map region (ccTLD)', blank=True)), - ('width', models.CharField(default=b'100%', help_text='Plugin width (in pixels or percent).', max_length=6, verbose_name='width')), - ('height', models.CharField(default=b'400px', help_text='Plugin height (in pixels).', max_length=6, verbose_name='height')), + ('width', models.CharField(default='100%', help_text='Plugin width (in pixels or percent).', max_length=6, verbose_name='width')), + ('height', models.CharField(default='400px', help_text='Plugin height (in pixels).', max_length=6, verbose_name='height')), ], options={ 'abstract': False, @@ -56,15 +57,15 @@ class Migration(migrations.Migration): migrations.CreateModel( name='EmbedSearchPlugin', fields=[ - ('cmsplugin_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')), + ('cmsplugin_ptr', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')), ('query', models.CharField(help_text='defines the place to highlight on the map. It accepts a location as either a place name or address', max_length=255, verbose_name='Query')), - ('map_type', models.CharField(default=b'roadmap', max_length=300, verbose_name='Map Type', choices=[(b'roadmap', 'Roadmap'), (b'satellite', 'Satellite')])), + ('map_type', models.CharField(default='roadmap', max_length=300, verbose_name='Map Type', choices=[('roadmap', 'Roadmap'), ('satellite', 'Satellite')])), ('center', models.CharField(help_text='optionally define the center of the map view. It accepts a comma-separated latitude and longitude value (such as 37.4218,-122.0840).', max_length=255, null=True, verbose_name='Center of the map (latitude + longitude)', blank=True)), - ('zoom', models.CharField(choices=[(b'0', b'0'), (b'1', b'1'), (b'2', b'2'), (b'3', b'3'), (b'4', b'4'), (b'5', b'5'), (b'6', b'6'), (b'7', b'7'), (b'8', b'8'), (b'9', b'9'), (b'10', b'10'), (b'11', b'11'), (b'12', b'12'), (b'13', b'13'), (b'14', b'14'), (b'15', b'15'), (b'16', b'16'), (b'17', b'17'), (b'18', b'18'), (b'19', b'19'), (b'20', b'20'), (b'21', b'21')], max_length=2, blank=True, help_text='0 (the whole world) to 21 (individual buildings). Leave empty for auto zoom', null=True, verbose_name='Zoom level')), + ('zoom', models.CharField(choices=[('0', '0'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11'), ('12', '12'), ('13', '13'), ('14', '14'), ('15', '15'), ('16', '16'), ('17', '17'), ('18', '18'), ('19', '19'), ('20', '20'), ('21', '21')], max_length=2, blank=True, help_text='0 (the whole world) to 21 (individual buildings). Leave empty for auto zoom', null=True, verbose_name='Zoom level')), ('ui_lang', models.CharField(help_text='default to page language', max_length=10, null=True, verbose_name='language for ui elements', blank=True)), ('region', models.CharField(help_text=' defines the appropriate borders and labels to display, based on geo-political sensitivities. Accepts a region code specified as a two-character ccTLD (top-level domain) value.', max_length=10, null=True, verbose_name='map region (ccTLD)', blank=True)), - ('width', models.CharField(default=b'100%', help_text='Plugin width (in pixels or percent).', max_length=6, verbose_name='width')), - ('height', models.CharField(default=b'400px', help_text='Plugin height (in pixels).', max_length=6, verbose_name='height')), + ('width', models.CharField(default='100%', help_text='Plugin width (in pixels or percent).', max_length=6, verbose_name='width')), + ('height', models.CharField(default='400px', help_text='Plugin height (in pixels).', max_length=6, verbose_name='height')), ], options={ 'abstract': False, @@ -74,15 +75,15 @@ class Migration(migrations.Migration): migrations.CreateModel( name='EmbedViewPlugin', fields=[ - ('cmsplugin_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')), + ('cmsplugin_ptr', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')), ('query', models.CharField(help_text='defines the place to highlight on the map. It accepts a location as either a place name or address', max_length=255, verbose_name='Query')), - ('map_type', models.CharField(default=b'roadmap', max_length=300, verbose_name='Map Type', choices=[(b'roadmap', 'Roadmap'), (b'satellite', 'Satellite')])), + ('map_type', models.CharField(default='roadmap', max_length=300, verbose_name='Map Type', choices=[('roadmap', 'Roadmap'), ('satellite', 'Satellite')])), ('center', models.CharField(help_text='optionally define the center of the map view. It accepts a comma-separated latitude and longitude value (such as 37.4218,-122.0840).', max_length=255, null=True, verbose_name='Center of the map (latitude + longitude)', blank=True)), - ('zoom', models.CharField(choices=[(b'0', b'0'), (b'1', b'1'), (b'2', b'2'), (b'3', b'3'), (b'4', b'4'), (b'5', b'5'), (b'6', b'6'), (b'7', b'7'), (b'8', b'8'), (b'9', b'9'), (b'10', b'10'), (b'11', b'11'), (b'12', b'12'), (b'13', b'13'), (b'14', b'14'), (b'15', b'15'), (b'16', b'16'), (b'17', b'17'), (b'18', b'18'), (b'19', b'19'), (b'20', b'20'), (b'21', b'21')], max_length=2, blank=True, help_text='0 (the whole world) to 21 (individual buildings). Leave empty for auto zoom', null=True, verbose_name='Zoom level')), + ('zoom', models.CharField(choices=[('0', '0'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11'), ('12', '12'), ('13', '13'), ('14', '14'), ('15', '15'), ('16', '16'), ('17', '17'), ('18', '18'), ('19', '19'), ('20', '20'), ('21', '21')], max_length=2, blank=True, help_text='0 (the whole world) to 21 (individual buildings). Leave empty for auto zoom', null=True, verbose_name='Zoom level')), ('ui_lang', models.CharField(help_text='default to page language', max_length=10, null=True, verbose_name='language for ui elements', blank=True)), ('region', models.CharField(help_text=' defines the appropriate borders and labels to display, based on geo-political sensitivities. Accepts a region code specified as a two-character ccTLD (top-level domain) value.', max_length=10, null=True, verbose_name='map region (ccTLD)', blank=True)), - ('width', models.CharField(default=b'100%', help_text='Plugin width (in pixels or percent).', max_length=6, verbose_name='width')), - ('height', models.CharField(default=b'400px', help_text='Plugin height (in pixels).', max_length=6, verbose_name='height')), + ('width', models.CharField(default='100%', help_text='Plugin width (in pixels or percent).', max_length=6, verbose_name='width')), + ('height', models.CharField(default='400px', help_text='Plugin height (in pixels).', max_length=6, verbose_name='height')), ], options={ 'abstract': False, @@ -92,7 +93,7 @@ class Migration(migrations.Migration): migrations.CreateModel( name='LocationPlugin', fields=[ - ('cmsplugin_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')), + ('cmsplugin_ptr', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')), ('address', models.CharField(max_length=150, verbose_name='address')), ('zipcode', models.CharField(max_length=30, verbose_name='zip code')), ('city', models.CharField(max_length=100, verbose_name='city')), @@ -108,12 +109,12 @@ class Migration(migrations.Migration): migrations.CreateModel( name='MapPlugin', fields=[ - ('cmsplugin_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')), + ('cmsplugin_ptr', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')), ('title', models.CharField(max_length=100, null=True, verbose_name='map title', blank=True)), - ('zoom', models.CharField(choices=[(b'0', b'0'), (b'1', b'1'), (b'2', b'2'), (b'3', b'3'), (b'4', b'4'), (b'5', b'5'), (b'6', b'6'), (b'7', b'7'), (b'8', b'8'), (b'9', b'9'), (b'10', b'10'), (b'11', b'11'), (b'12', b'12'), (b'13', b'13'), (b'14', b'14'), (b'15', b'15'), (b'16', b'16'), (b'17', b'17'), (b'18', b'18'), (b'19', b'19'), (b'20', b'20'), (b'21', b'21')], max_length=20, blank=True, help_text='Leave empty for auto zoom', null=True, verbose_name='Zoom level')), + ('zoom', models.CharField(choices=[('0', '0'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11'), ('12', '12'), ('13', '13'), ('14', '14'), ('15', '15'), ('16', '16'), ('17', '17'), ('18', '18'), ('19', '19'), ('20', '20'), ('21', '21')], max_length=20, blank=True, help_text='Leave empty for auto zoom', null=True, verbose_name='Zoom level')), ('route_planner_title', models.CharField(default='Calculate your fastest way to here', max_length=150, null=True, verbose_name='Route Planner Title', blank=True)), - ('width', models.CharField(default=b'100%', help_text='Plugin width (in pixels or percent).', max_length=6, verbose_name='width')), - ('height', models.CharField(default=b'400px', help_text='Plugin height (in pixels).', max_length=6, verbose_name='height')), + ('width', models.CharField(default='100%', help_text='Plugin width (in pixels or percent).', max_length=6, verbose_name='width')), + ('height', models.CharField(default='400px', help_text='Plugin height (in pixels).', max_length=6, verbose_name='height')), ('scrollwheel', models.BooleanField(default=True, verbose_name='Enable scrollwheel zooming on the map')), ('double_click_zoom', models.BooleanField(default=True, verbose_name='Enable double click to zoom')), ('draggable', models.BooleanField(default=True, verbose_name='Allow map dragging')), @@ -121,7 +122,7 @@ class Migration(migrations.Migration): ('pan_control', models.BooleanField(default=True, verbose_name='Show pan control')), ('zoom_control', models.BooleanField(default=True, verbose_name='Show zoom control')), ('street_view_control', models.BooleanField(default=True, verbose_name='Show Street View control')), - ('map_type', models.CharField(default=b'roadmap', max_length=300, verbose_name='Map Type', choices=[(b'roadmap', 'Roadmap'), (b'satellite', 'Satellite'), (b'hybrid', 'Hybrid'), (b'terrain', 'Terrain')])), + ('map_type', models.CharField(default='roadmap', max_length=300, verbose_name='Map Type', choices=[('roadmap', 'Roadmap'), ('satellite', 'Satellite'), ('hybrid', 'Hybrid'), ('terrain', 'Terrain')])), ], options={ 'abstract': False, @@ -131,7 +132,7 @@ class Migration(migrations.Migration): migrations.CreateModel( name='RouteLocationPlugin', fields=[ - ('locationplugin_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='aldryn_locations.LocationPlugin')), + ('locationplugin_ptr', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, auto_created=True, primary_key=True, serialize=False, to='aldryn_locations.LocationPlugin')), ], options={ 'abstract': False, diff --git a/aldryn_locations/migrations/0002_bump_max_lengths.py b/aldryn_locations/migrations/0002_bump_max_lengths.py index 3bdd899..ae228cb 100644 --- a/aldryn_locations/migrations/0002_bump_max_lengths.py +++ b/aldryn_locations/migrations/0002_bump_max_lengths.py @@ -14,62 +14,62 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='embeddirectionsplugin', name='height', - field=models.CharField(default=b'400px', help_text='Plugin height (in pixels).', max_length=255, verbose_name='height'), + field=models.CharField(default='400px', help_text='Plugin height (in pixels).', max_length=255, verbose_name='height'), ), migrations.AlterField( model_name='embeddirectionsplugin', name='map_type', - field=models.CharField(default=b'roadmap', max_length=255, verbose_name='Map Type', choices=[(b'roadmap', 'Roadmap'), (b'satellite', 'Satellite')]), + field=models.CharField(default='roadmap', max_length=255, verbose_name='Map Type', choices=[('roadmap', 'Roadmap'), ('satellite', 'Satellite')]), ), migrations.AlterField( model_name='embeddirectionsplugin', name='width', - field=models.CharField(default=b'100%', help_text='Plugin width (in pixels or percent).', max_length=255, verbose_name='width'), + field=models.CharField(default='100%', help_text='Plugin width (in pixels or percent).', max_length=255, verbose_name='width'), ), migrations.AlterField( model_name='embedplaceplugin', name='height', - field=models.CharField(default=b'400px', help_text='Plugin height (in pixels).', max_length=255, verbose_name='height'), + field=models.CharField(default='400px', help_text='Plugin height (in pixels).', max_length=255, verbose_name='height'), ), migrations.AlterField( model_name='embedplaceplugin', name='map_type', - field=models.CharField(default=b'roadmap', max_length=255, verbose_name='Map Type', choices=[(b'roadmap', 'Roadmap'), (b'satellite', 'Satellite')]), + field=models.CharField(default='roadmap', max_length=255, verbose_name='Map Type', choices=[('roadmap', 'Roadmap'), ('satellite', 'Satellite')]), ), migrations.AlterField( model_name='embedplaceplugin', name='width', - field=models.CharField(default=b'100%', help_text='Plugin width (in pixels or percent).', max_length=255, verbose_name='width'), + field=models.CharField(default='100%', help_text='Plugin width (in pixels or percent).', max_length=255, verbose_name='width'), ), migrations.AlterField( model_name='embedsearchplugin', name='height', - field=models.CharField(default=b'400px', help_text='Plugin height (in pixels).', max_length=255, verbose_name='height'), + field=models.CharField(default='400px', help_text='Plugin height (in pixels).', max_length=255, verbose_name='height'), ), migrations.AlterField( model_name='embedsearchplugin', name='map_type', - field=models.CharField(default=b'roadmap', max_length=255, verbose_name='Map Type', choices=[(b'roadmap', 'Roadmap'), (b'satellite', 'Satellite')]), + field=models.CharField(default='roadmap', max_length=255, verbose_name='Map Type', choices=[('roadmap', 'Roadmap'), ('satellite', 'Satellite')]), ), migrations.AlterField( model_name='embedsearchplugin', name='width', - field=models.CharField(default=b'100%', help_text='Plugin width (in pixels or percent).', max_length=255, verbose_name='width'), + field=models.CharField(default='100%', help_text='Plugin width (in pixels or percent).', max_length=255, verbose_name='width'), ), migrations.AlterField( model_name='embedviewplugin', name='height', - field=models.CharField(default=b'400px', help_text='Plugin height (in pixels).', max_length=255, verbose_name='height'), + field=models.CharField(default='400px', help_text='Plugin height (in pixels).', max_length=255, verbose_name='height'), ), migrations.AlterField( model_name='embedviewplugin', name='map_type', - field=models.CharField(default=b'roadmap', max_length=255, verbose_name='Map Type', choices=[(b'roadmap', 'Roadmap'), (b'satellite', 'Satellite')]), + field=models.CharField(default='roadmap', max_length=255, verbose_name='Map Type', choices=[('roadmap', 'Roadmap'), ('satellite', 'Satellite')]), ), migrations.AlterField( model_name='embedviewplugin', name='width', - field=models.CharField(default=b'100%', help_text='Plugin width (in pixels or percent).', max_length=255, verbose_name='width'), + field=models.CharField(default='100%', help_text='Plugin width (in pixels or percent).', max_length=255, verbose_name='width'), ), migrations.AlterField( model_name='locationplugin', @@ -89,12 +89,12 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='mapplugin', name='height', - field=models.CharField(default=b'400px', help_text='Plugin height (in pixels).', max_length=255, verbose_name='height'), + field=models.CharField(default='400px', help_text='Plugin height (in pixels).', max_length=255, verbose_name='height'), ), migrations.AlterField( model_name='mapplugin', name='map_type', - field=models.CharField(default=b'roadmap', max_length=255, verbose_name='Map Type', choices=[(b'roadmap', 'Roadmap'), (b'satellite', 'Satellite'), (b'hybrid', 'Hybrid'), (b'terrain', 'Terrain')]), + field=models.CharField(default='roadmap', max_length=255, verbose_name='Map Type', choices=[('roadmap', 'Roadmap'), ('satellite', 'Satellite'), ('hybrid', 'Hybrid'), ('terrain', 'Terrain')]), ), migrations.AlterField( model_name='mapplugin', @@ -109,6 +109,6 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='mapplugin', name='width', - field=models.CharField(default=b'100%', help_text='Plugin width (in pixels or percent).', max_length=255, verbose_name='width'), + field=models.CharField(default='100%', help_text='Plugin width (in pixels or percent).', max_length=255, verbose_name='width'), ), ] diff --git a/aldryn_locations/migrations/0003_path file location.py b/aldryn_locations/migrations/0003_path file location.py index 38244ec..faa7b83 100644 --- a/aldryn_locations/migrations/0003_path file location.py +++ b/aldryn_locations/migrations/0003_path file location.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from django.db import migrations, models +import django.db.models.deletion import filer.fields.file @@ -17,8 +18,8 @@ class Migration(migrations.Migration): migrations.CreateModel( name='PathLocationPlugin', fields=[ - ('cmsplugin_ptr', models.OneToOneField(parent_link=True, related_name='aldryn_locations_pathlocationplugin', auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')), - ('path_file', filer.fields.file.FilerFileField(related_name='+', verbose_name='Path File (e.g. KML)', to='filer.File')), + ('cmsplugin_ptr', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, related_name='aldryn_locations_pathlocationplugin', auto_created=True, primary_key=True, serialize=False, to='cms.CMSPlugin')), + ('path_file', filer.fields.file.FilerFileField(on_delete=django.db.models.deletion.CASCADE, related_name='+', verbose_name='Path File (e.g. KML)', to='filer.File')), ], options={ 'abstract': False, diff --git a/aldryn_locations/migrations/0004_auto_20160914_1511.py b/aldryn_locations/migrations/0004_auto_20160914_1511.py index 37b368e..ad7a56e 100644 --- a/aldryn_locations/migrations/0004_auto_20160914_1511.py +++ b/aldryn_locations/migrations/0004_auto_20160914_1511.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from django.db import migrations, models +import django.db.models.deletion class Migration(migrations.Migration): @@ -14,36 +15,36 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='embeddirectionsplugin', name='cmsplugin_ptr', - field=models.OneToOneField(parent_link=True, related_name='aldryn_locations_embeddirectionsplugin', primary_key=True, serialize=False, to='cms.CMSPlugin'), + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, related_name='aldryn_locations_embeddirectionsplugin', primary_key=True, serialize=False, to='cms.CMSPlugin'), ), migrations.AlterField( model_name='embedplaceplugin', name='cmsplugin_ptr', - field=models.OneToOneField(parent_link=True, related_name='aldryn_locations_embedplaceplugin', primary_key=True, serialize=False, to='cms.CMSPlugin'), + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, related_name='aldryn_locations_embedplaceplugin', primary_key=True, serialize=False, to='cms.CMSPlugin'), ), migrations.AlterField( model_name='embedsearchplugin', name='cmsplugin_ptr', - field=models.OneToOneField(parent_link=True, related_name='aldryn_locations_embedsearchplugin', primary_key=True, serialize=False, to='cms.CMSPlugin'), + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, related_name='aldryn_locations_embedsearchplugin', primary_key=True, serialize=False, to='cms.CMSPlugin'), ), migrations.AlterField( model_name='embedviewplugin', name='cmsplugin_ptr', - field=models.OneToOneField(parent_link=True, related_name='aldryn_locations_embedviewplugin', primary_key=True, serialize=False, to='cms.CMSPlugin'), + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, related_name='aldryn_locations_embedviewplugin', primary_key=True, serialize=False, to='cms.CMSPlugin'), ), migrations.AlterField( model_name='locationplugin', name='cmsplugin_ptr', - field=models.OneToOneField(parent_link=True, related_name='aldryn_locations_locationplugin', primary_key=True, serialize=False, to='cms.CMSPlugin'), + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, related_name='aldryn_locations_locationplugin', primary_key=True, serialize=False, to='cms.CMSPlugin'), ), migrations.AlterField( model_name='mapplugin', name='cmsplugin_ptr', - field=models.OneToOneField(parent_link=True, related_name='aldryn_locations_mapplugin', primary_key=True, serialize=False, to='cms.CMSPlugin'), + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, related_name='aldryn_locations_mapplugin', primary_key=True, serialize=False, to='cms.CMSPlugin'), ), migrations.AlterField( model_name='pathlocationplugin', name='cmsplugin_ptr', - field=models.OneToOneField(parent_link=True, related_name='aldryn_locations_pathlocationplugin', primary_key=True, serialize=False, to='cms.CMSPlugin'), + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, related_name='aldryn_locations_pathlocationplugin', primary_key=True, serialize=False, to='cms.CMSPlugin'), ), ] diff --git a/aldryn_locations/migrations/0005_auto_20180507_1427.py b/aldryn_locations/migrations/0005_auto_20180507_1427.py new file mode 100644 index 0000000..a00a15c --- /dev/null +++ b/aldryn_locations/migrations/0005_auto_20180507_1427.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-05-07 04:27 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('aldryn_locations', '0004_auto_20160914_1511'), + ] + + operations = [ + migrations.RemoveField( + model_name='embeddirectionsplugin', + name='query', + ), + migrations.RemoveField( + model_name='embedviewplugin', + name='query', + ), + ] diff --git a/aldryn_locations/migrations/0006_fix_broken_routelocation_plugin.py b/aldryn_locations/migrations/0006_fix_broken_routelocation_plugin.py new file mode 100644 index 0000000..c0bd7b9 --- /dev/null +++ b/aldryn_locations/migrations/0006_fix_broken_routelocation_plugin.py @@ -0,0 +1,121 @@ +# Generated by Django 2.2.9 on 2020-06-23 18:56 +import django.db.models.deletion +from cms import api +from cms.models import CMSPlugin +from cms.models import Placeholder +from django.db import migrations +from django.db import models + + +def transfer_route_location_plugin_data(apps, schema_editor): + + RouteLocationPluginTemp = apps.get_model('aldryn_locations', 'RouteLocationPluginTemp') + + for temp_plugin in RouteLocationPluginTemp.objects.all(): + old_plugin = CMSPlugin.objects.get(pk=temp_plugin.pk) + placeholder_with_old_plugin = Placeholder.objects.get(pk=old_plugin.placeholder.pk) + page_with_old_plugin = placeholder_with_old_plugin.page + + if _is_page_published(page_with_old_plugin): + draft_page = page_with_old_plugin.get_draft_object() + draft_placeholder = draft_page.placeholders.get(slot=placeholder_with_old_plugin.slot) + draft_plugins = draft_placeholder.get_plugins() + draft_parent_map_plugins = list( + filter( + lambda x: ( + x.get_bound_plugin().plugin_type == old_plugin.parent.get_bound_plugin().plugin_type and + x.get_bound_plugin().title == old_plugin.parent.get_bound_plugin().title and + _is_numchild_value_broken(x) + ), + draft_plugins + ) + ) + + if draft_parent_map_plugins: + # For now we'll take the first available MapPlugin in the placeholder + draft_parent_map_plugin = draft_parent_map_plugins[0] + + # Fix the broken numchild field's value + draft_parent_map_plugin.numchild = draft_parent_map_plugin.get_children().count() + draft_parent_map_plugin.save() + + api.add_plugin( + placeholder=draft_placeholder, + language=temp_plugin.language, + target=draft_parent_map_plugin, + address=temp_plugin.address, + zipcode=temp_plugin.zipcode, + city=temp_plugin.city, + content=temp_plugin.content, + depth=temp_plugin.depth, + plugin_type=temp_plugin.plugin_type, + creation_date=temp_plugin.creation_date, + changed_date=temp_plugin.changed_date, + lat=temp_plugin.lat, + lng=temp_plugin.lng, + ) + else: + print( + "Failed to find the needed Map plugin on the Draft version of Page. " + "Most probably it doesn't exist anymore." + ) + + api.add_plugin( + placeholder=placeholder_with_old_plugin, + language=temp_plugin.language, + target=old_plugin.parent, + address=temp_plugin.address, + zipcode=temp_plugin.zipcode, + city=temp_plugin.city, + content=temp_plugin.content, + depth=temp_plugin.depth, + plugin_type=temp_plugin.plugin_type, + creation_date=temp_plugin.creation_date, + changed_date=temp_plugin.changed_date, + lat=temp_plugin.lat, + lng=temp_plugin.lng, + ) + + +def _is_numchild_value_broken(plugin): + # The 'numchild' value of broken plugins is greater than actual count of child plugins + return plugin.numchild > plugin.get_children().count() + + +def _is_page_published(page): + return not page.publisher_is_draft + + +class Migration(migrations.Migration): + + dependencies = [ + ('cms', '0022_auto_20180620_1551'), + ('aldryn_locations', '0005_auto_20180507_1427'), + ] + + operations = [ + migrations.RenameModel( + old_name='RouteLocationPlugin', + new_name='RouteLocationPluginTemp', + ), + migrations.CreateModel( + name='RouteLocationPlugin', + fields=[ + ('cmsplugin_ptr', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='aldryn_locations_routelocationplugin', serialize=False, to='cms.CMSPlugin')), + ('address', models.CharField(max_length=255, verbose_name='address')), + ('zipcode', models.CharField(max_length=30, verbose_name='zip code')), + ('city', models.CharField(max_length=255, verbose_name='city')), + ('content', models.CharField(blank=True, help_text='Displayed in a info window above location marker', max_length=255, verbose_name='Content')), + ('lat', models.FloatField(blank=True, help_text='Use latitude & longitude to fine tune the map position.', null=True, verbose_name='latitude')), + ('lng', models.FloatField(blank=True, null=True, verbose_name='longitude')), + ], + options={ + 'abstract': False, + }, + bases=('cms.cmsplugin',), + ), + migrations.RunPython(transfer_route_location_plugin_data), + migrations.DeleteModel( + name='RouteLocationPluginTemp', + ), + ] diff --git a/aldryn_locations/models.py b/aldryn_locations/models.py index 1ec7ac9..1d33db5 100644 --- a/aldryn_locations/models.py +++ b/aldryn_locations/models.py @@ -3,11 +3,11 @@ from django.template.defaultfilters import urlencode from django.utils.translation import ugettext_lazy as _ from django.conf import settings -from django.core.urlresolvers import reverse +from django.urls import reverse from cms.models import CMSPlugin, Site from cms.utils.i18n import get_current_language -from cms.utils.compat.dj import python_2_unicode_compatible +from six import python_2_unicode_compatible from filer.fields.file import FilerFileField @@ -18,7 +18,7 @@ 'ALDRYN_LOCATIONS_GOOGLEMAPS_STATICMAPS_URL', 'https://maps.googleapis.com/maps/api/staticmap', ) -MARKER_CONTENT_FORMAT = unicode(settings.ALDRYN_LOCATIONS_MARKER_CONTENT_FORMAT) +MARKER_CONTENT_FORMAT = str(settings.ALDRYN_LOCATIONS_MARKER_CONTENT_FORMAT) ZOOM_LEVELS = [(str(level), str(level)) for level in range(22)] ROADMAP = 'roadmap' @@ -43,6 +43,7 @@ class MapPlugin(CMSPlugin): CMSPlugin, related_name='%(app_label)s_%(class)s', parent_link=True, + on_delete=models.CASCADE, ) title = models.CharField(_("map title"), max_length=255, blank=True, @@ -143,7 +144,7 @@ def clean_size(size): lat_lng = location.get_lat_lng() location = ( - ','.join(lat_lng) if lat_lng else + ','.join(map(str, lat_lng)) if lat_lng else ' '.join((location.address, location.zipcode, location.city)) ) query += '&markers={}'.format(urlencode(location)) @@ -165,6 +166,7 @@ class LocationPlugin(CMSPlugin): CMSPlugin, related_name='%(app_label)s_%(class)s', parent_link=True, + on_delete=models.CASCADE, ) address = models.CharField(_("address"), max_length=255) @@ -217,9 +219,65 @@ def get_location_data_for_map(self): } -class RouteLocationPlugin(LocationPlugin): +class RouteLocationPlugin(CMSPlugin): route_planner = True + cmsplugin_ptr = models.OneToOneField( + CMSPlugin, + related_name='%(app_label)s_%(class)s', + parent_link=True, + on_delete=models.CASCADE, + ) + + address = models.CharField(_("address"), max_length=255) + zipcode = models.CharField(_("zip code"), max_length=30) + city = models.CharField(_("city"), max_length=255) + + content = models.CharField( + _('Content'), max_length=255, blank=True, + help_text=_('Displayed in a info window above location marker') + ) + + lat = models.FloatField( + _('latitude'), null=True, blank=True, + help_text=_('Use latitude & longitude to fine tune the map position.')) + + lng = models.FloatField( + _('longitude'), null=True, blank=True) + + def __str__(self): + return u'%s, %s %s' % (self.address, self.zipcode, self.city) + + def get_content(self): + if not self.content: + return None + + fmt = MARKER_CONTENT_FORMAT + + if not fmt: + return self.content + + return fmt.format( + content=self.content, + address=self.address, + zipcode=self.zipcode, + city=self.city, + lat=self.lat, + lng=self.lng, + ) + + def get_lat_lng(self): + if self.lat and self.lng: + return self.lat, self.lng + + def get_location_data_for_map(self): + return { + 'address': u'{}, {} {}'.format(self.address, self.zipcode, self.city), + 'latlng': self.get_lat_lng(), + 'content': self.get_content(), + 'admin': reverse('admin:cms_page_edit_plugin', args=[self.pk]), + } + class PathLocationPlugin(CMSPlugin): route_planner = False @@ -228,17 +286,19 @@ class PathLocationPlugin(CMSPlugin): CMSPlugin, related_name='%(app_label)s_%(class)s', parent_link=True, + on_delete=models.CASCADE, ) path_file = FilerFileField( verbose_name=_('Path File (e.g. KML)'), related_name='+', + on_delete=models.CASCADE, ) def copy_relations(self, oldinstance): self.path_file = oldinstance.path_file - def __unicode__(self): + def __str__(self): if self.path_file: return self.path_file.name return self.pk @@ -257,6 +317,7 @@ class EmbedPlugin(CMSPlugin): CMSPlugin, related_name='%(app_label)s_%(class)s', parent_link=True, + on_delete=models.CASCADE, ) query = models.CharField( @@ -293,7 +354,7 @@ class EmbedPlugin(CMSPlugin): class Meta: abstract = True - def __unicode__(self): + def __str__(self): return self.query or self.center def get_query(self): @@ -410,7 +471,7 @@ class EmbedDirectionsPlugin(EmbedPlugin): units = models.CharField( _('units for distances in results'), max_length=10, default=AUTO[0], choices=[AUTO] + UNITS_CHOICES) - def __unicode__(self): + def __str__(self): ret = self.origin if self.waypoints: ret += ' -> %s' % ' -> '.join(self.waypoints.split('|')) diff --git a/setup.py b/setup.py index 527c077..b718808 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ REQUIREMENTS = [ 'aldryn-boilerplates>=0.6', 'django-filer', + 'six', ] CLASSIFIERS = [