diff --git a/.travis.yml b/.travis.yml index cc3bc52..dec9cf6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ env: - DJANGO=1.8.14 - DJANGO=1.9.9 - DJANGO=1.10 + - DJANGO=1.11 install: - pip install -q Django==$DJANGO - pip install . diff --git a/geoposition/__init__.py b/geoposition/__init__.py index eafb2f2..de44de8 100644 --- a/geoposition/__init__.py +++ b/geoposition/__init__.py @@ -3,7 +3,7 @@ default_app_config = 'geoposition.apps.GeoPositionConfig' -VERSION = (0, 3, 0) +VERSION = (0, 3, 1) __version__ = '.'.join(map(str, VERSION)) diff --git a/geoposition/templates/geoposition/widgets/geoposition.html b/geoposition/templates/geoposition/widgets/geoposition.html index e621ad4..bdd44d9 100644 --- a/geoposition/templates/geoposition/widgets/geoposition.html +++ b/geoposition/templates/geoposition/widgets/geoposition.html @@ -2,11 +2,23 @@ - + - +
{{ latitude.label|capfirst }}{{ latitude.html }} + {% if latitude.widget %} + {% include latitude.widget.template_name with widget=latitude.widget %} + {% else %} + {{ latitude.html }} + {% endif %} +
{{ longitude.label|capfirst }}{{ longitude.html }} + {% if longitude.widget %} + {% include longitude.widget.template_name with widget=longitude.widget %} + {% else %} + {{ longitude.html }} + {% endif %} +
diff --git a/geoposition/widgets.py b/geoposition/widgets.py index e2b82a1..99a1736 100644 --- a/geoposition/widgets.py +++ b/geoposition/widgets.py @@ -1,14 +1,18 @@ from __future__ import unicode_literals import json + from django import forms from django.template.loader import render_to_string from django.utils import six from django.utils.translation import ugettext_lazy as _ + from .conf import settings class GeopositionWidget(forms.MultiWidget): + template_name = 'geoposition/widgets/geoposition.html' + def __init__(self, attrs=None): widgets = ( forms.TextInput(), @@ -23,7 +27,30 @@ def decompress(self, value): return [value.latitude, value.longitude] return [None, None] + def get_config(self): + return { + 'map_widget_height': settings.MAP_WIDGET_HEIGHT or 500, + 'map_options': json.dumps(settings.MAP_OPTIONS), + 'marker_options': json.dumps(settings.MARKER_OPTIONS), + } + + + def get_context(self, name, value, attrs): + # Django 1.11 and up + context = super(GeopositionWidget, self).get_context(name, value, attrs) + context['latitude'] = { + 'widget': context['widget']['subwidgets'][0], + 'label': _("latitude"), + } + context['longitude'] = { + 'widget': context['widget']['subwidgets'][1], + 'label': _("longitude"), + } + context['config'] = self.get_config() + return context + def format_output(self, rendered_widgets): + # Django 1.10 and down return render_to_string('geoposition/widgets/geoposition.html', { 'latitude': { 'html': rendered_widgets[0], @@ -33,11 +60,7 @@ def format_output(self, rendered_widgets): 'html': rendered_widgets[1], 'label': _("longitude"), }, - 'config': { - 'map_widget_height': settings.MAP_WIDGET_HEIGHT or 500, - 'map_options': json.dumps(settings.MAP_OPTIONS), - 'marker_options': json.dumps(settings.MARKER_OPTIONS), - } + 'config': self.get_config(), }) class Media: