diff options
Diffstat (limited to 'chimere/widgets.py')
-rw-r--r-- | chimere/widgets.py | 63 |
1 files changed, 21 insertions, 42 deletions
diff --git a/chimere/widgets.py b/chimere/widgets.py index b60a661..87f797a 100644 --- a/chimere/widgets.py +++ b/chimere/widgets.py @@ -29,6 +29,7 @@ from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse from django.utils.safestring import mark_safe from django.utils.translation import ugettext as _ +from django.template.loader import render_to_string import re @@ -182,49 +183,27 @@ class PointChooserWidget(forms.TextInput): else: value = None map_layers, default_area = get_map_layers(area_name) - js = """ - OpenLayers.ImgPath = '%schimere/img/'; - var EPSG_DISPLAY_PROJECTION = epsg_display_projection = new OpenLayers.Projection('EPSG:%s'); - var EPSG_PROJECTION = epsg_projection = new OpenLayers.Projection('EPSG:%s'); - var CENTER_LONLAT = centerLonLat = new OpenLayers.LonLat%s.transform(epsg_display_projection, epsg_projection); - var DEFAULT_ZOOM = %s; - var chimere_init_options = {}; - chimere_init_options["default_icon"] = new OpenLayers.Icon('%schimere/img/marker-green.png', new OpenLayers.Size(21, 25), new OpenLayers.Pixel(-(21/2), -25)); - chimere_init_options["map_layers"] = [%s]; - chimere_init_options['dynamic_categories'] = false; - chimere_init_options['edition'] = true; - chimere_init_options["checked_categories"] = []; - """ % (settings.STATIC_URL, settings.CHIMERE_EPSG_DISPLAY_PROJECTION, - settings.CHIMERE_EPSG_PROJECTION, settings.CHIMERE_DEFAULT_CENTER, - settings.CHIMERE_DEFAULT_ZOOM, settings.STATIC_URL, - ", ".join(map_layers)) - if default_area: - js += "chimere_init_options['selected_map_layer'] = %d;\n" % \ - default_area #TODO: manage area - tpl = u"<script type='text/javascript'><!--\n"\ - u"%s// !--></script>\n" % js - tpl += u"</div><div id='map_edit'></div>"\ - u"<div id='live_lonlat'>"\ - u" <p><label for='live_latitude'>%s</label>"\ - u" <input type='texte' name='live_latitude' id='live_latitude' "\ - u"size='8' disabled='true' value='%f'/></p>"\ - u"<p><label for='live_longitude'>%s</label><input type='texte' "\ - u"name='live_longitude' id='live_longitude' size='8' "\ - u"disabled='true' value='%f'/></p>"\ - u"<input type='hidden' name='%s' id='id_%s' value='%s'/>" % ( - _("Latitude"), value_y, _("Longitude"), value_x, name, name, - val) - tpl += "<script type='text/javascript'><!--\n" - tpl += "$('#map_edit').chimere(chimere_init_options);\n" - if value: - tpl += u'var mylonlat = new OpenLayers.LonLat(%f,%f);\n'\ - u'$("#map_edit").chimere("putEditMarker", \n'\ - u' mylonlat.transform(EPSG_DISPLAY_PROJECTION, \n'\ - u' EPSG_PROJECTION), true);\n' % ( - value_x, value_y) - tpl += "// --></script>\n" - return mark_safe(tpl) + return mark_safe( + render_to_string('chimere/blocks/live_coordinates.html', + {'lat': _("Latitude"), + 'value_y': value_y, + 'lon': _("Longitude"), + 'value_x': value_x, + 'name': name, + 'val': val, + 'isvalue': "true" if value else "false", + 'default_area': "true" if default_area else "false", + }) % \ + (settings.STATIC_URL, + settings.CHIMERE_EPSG_DISPLAY_PROJECTION, + settings.CHIMERE_EPSG_PROJECTION, + settings.CHIMERE_DEFAULT_CENTER, + settings.CHIMERE_DEFAULT_ZOOM, + settings.STATIC_URL, + ", ".join(map_layers) + ) + ) class PointField(models.PointField): ''' |