diff options
| author | Preston Timmons <prestontimmons@gmail.com> | 2016-12-27 17:00:56 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-12-27 17:50:10 -0500 |
| commit | b52c73008a9d67e9ddbb841872dc15cdd3d6ee01 (patch) | |
| tree | b58a2d18242db5234b18678116e07e6f6bbc7cb3 /django/contrib/gis | |
| parent | 51cde873d9fc8e4540f4efecbd39cfe8e770be38 (diff) | |
Fixed #15667 -- Added template-based widget rendering.
Thanks Carl Meyer and Tim Graham for contributing to the patch.
Diffstat (limited to 'django/contrib/gis')
| -rw-r--r-- | django/contrib/gis/admin/options.py | 2 | ||||
| -rw-r--r-- | django/contrib/gis/admin/widgets.py | 5 | ||||
| -rw-r--r-- | django/contrib/gis/forms/widgets.py | 14 |
3 files changed, 11 insertions, 10 deletions
diff --git a/django/contrib/gis/admin/options.py b/django/contrib/gis/admin/options.py index 4b99ddf354..4ae61661d3 100644 --- a/django/contrib/gis/admin/options.py +++ b/django/contrib/gis/admin/options.py @@ -80,7 +80,7 @@ class GeoModelAdmin(ModelAdmin): collection_type = 'None' class OLMap(self.widget): - template = self.map_template + template_name = self.map_template geom_type = db_field.geom_type wms_options = '' diff --git a/django/contrib/gis/admin/widgets.py b/django/contrib/gis/admin/widgets.py index bf6340d239..014b3ad818 100644 --- a/django/contrib/gis/admin/widgets.py +++ b/django/contrib/gis/admin/widgets.py @@ -3,7 +3,6 @@ import logging from django.contrib.gis.gdal import GDALException from django.contrib.gis.geos import GEOSException, GEOSGeometry from django.forms.widgets import Textarea -from django.template import loader from django.utils import six, translation # Creating a template context that contains Django settings @@ -16,7 +15,7 @@ class OpenLayersWidget(Textarea): """ Renders an OpenLayers map using the WKT of the geometry. """ - def render(self, name, value, attrs=None): + def get_context(self, name, value, attrs=None): # Update the template parameters with any attributes passed in. if attrs: self.params.update(attrs) @@ -77,7 +76,7 @@ class OpenLayersWidget(Textarea): self.params['wkt'] = wkt self.params.update(geo_context) - return loader.render_to_string(self.template, self.params) + return self.params def map_options(self): "Builds the map options hash for the OpenLayers template." diff --git a/django/contrib/gis/forms/widgets.py b/django/contrib/gis/forms/widgets.py index 7b58d5a477..37e58d9b74 100644 --- a/django/contrib/gis/forms/widgets.py +++ b/django/contrib/gis/forms/widgets.py @@ -6,7 +6,6 @@ from django.conf import settings from django.contrib.gis import gdal from django.contrib.gis.geos import GEOSException, GEOSGeometry from django.forms.widgets import Widget -from django.template import loader from django.utils import six, translation logger = logging.getLogger('django.contrib.gis') @@ -43,7 +42,7 @@ class BaseGeometryWidget(Widget): logger.error("Error creating geometry from value '%s' (%s)", value, err) return None - def render(self, name, value, attrs=None): + def get_context(self, name, value, attrs=None): # If a string reaches here (via a validation error on another # field) then just reconstruct the Geometry. if value and isinstance(value, six.string_types): @@ -62,16 +61,19 @@ class BaseGeometryWidget(Widget): value.srid, self.map_srid, err ) - context = self.build_attrs( - attrs, + if attrs is None: + attrs = {} + + context = self.build_attrs(self.attrs, dict( name=name, module='geodjango_%s' % name.replace('-', '_'), # JS-safe serialized=self.serialize(value), geom_type=gdal.OGRGeomType(self.attrs['geom_type']), STATIC_URL=settings.STATIC_URL, LANGUAGE_BIDI=translation.get_language_bidi(), - ) - return loader.render_to_string(self.template_name, context) + **attrs + )) + return context class OpenLayersWidget(BaseGeometryWidget): |
