~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to django/contrib/gis/forms/widgets.py

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog
  • Date: 2014-09-17 14:15:11 UTC
  • mfrom: (1.3.17) (6.2.18 experimental)
  • Revision ID: package-import@ubuntu.com-20140917141511-icneokthe9ww5sk4
Tags: 1.7-2
* Release to unstable.
* Add a migrate-south sample script to help users apply their South
  migrations. Thanks to Brian May.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
        except (GEOSException, ValueError) as err:
44
44
            logger.error(
45
45
                "Error creating geometry from value '%s' (%s)" % (
46
 
                value, err)
 
46
                    value, err)
47
47
            )
48
48
        return None
49
49
 
63
63
                except gdal.OGRException as err:
64
64
                    logger.error(
65
65
                        "Error transforming geometry from srid '%s' to srid '%s' (%s)" % (
66
 
                        value.srid, self.map_srid, err)
 
66
                            value.srid, self.map_srid, err)
67
67
                    )
68
68
 
69
 
        context = self.build_attrs(attrs,
 
69
        context = self.build_attrs(
 
70
            attrs,
70
71
            name=name,
71
 
            module='geodjango_%s' % name.replace('-','_'),  # JS-safe
 
72
            module='geodjango_%s' % name.replace('-', '_'),  # JS-safe
72
73
            serialized=self.serialize(value),
73
74
            geom_type=gdal.OGRGeomType(self.attrs['geom_type']),
74
75
            STATIC_URL=settings.STATIC_URL,
79
80
 
80
81
class OpenLayersWidget(BaseGeometryWidget):
81
82
    template_name = 'gis/openlayers.html'
 
83
 
82
84
    class Media:
83
85
        js = (
84
 
            'http://openlayers.org/api/2.11/OpenLayers.js',
 
86
            'http://openlayers.org/api/2.13/OpenLayers.js',
85
87
            'gis/js/OLMapWidget.js',
86
88
        )
87
89
 
96
98
 
97
99
    class Media:
98
100
        js = (
99
 
            'http://openlayers.org/api/2.11/OpenLayers.js',
 
101
            'http://openlayers.org/api/2.13/OpenLayers.js',
100
102
            'http://www.openstreetmap.org/openlayers/OpenStreetMap.js',
101
103
            'gis/js/OLMapWidget.js',
102
104
        )
103
105
 
 
106
    def __init__(self, attrs=None):
 
107
        super(OSMWidget, self).__init__()
 
108
        for key in ('default_lon', 'default_lat'):
 
109
            self.attrs[key] = getattr(self, key)
 
110
        if attrs:
 
111
            self.attrs.update(attrs)
 
112
 
104
113
    @property
105
114
    def map_srid(self):
106
115
        # Use the official spherical mercator projection SRID on versions
109
118
            return 3857
110
119
        else:
111
120
            return 900913
112
 
 
113
 
    def render(self, name, value, attrs=None):
114
 
        default_attrs = {
115
 
            'default_lon': self.default_lon,
116
 
            'default_lat': self.default_lat,
117
 
        }
118
 
        if attrs:
119
 
            default_attrs.update(attrs)
120
 
        return super(OSMWidget, self).render(name, value, default_attrs)