Ticket #10872: geodjango_widget_list_editable_support.patch

File geodjango_widget_list_editable_support.patch, 3.1 KB (added by springmeyer, 16 years ago)

Hack to get geodjango admin map widget working with post data

  • django/contrib/gis/admin/widgets.py

     
    3737
    3838        # Constructing the dictionary of the map options.
    3939        self.params['map_options'] = self.map_options()
    40 
     40       
     41        # hidden widgets don't set attrs in the same way as other widgets
     42        # and therefore seem to accept the auto_id from here:
     43        # http://code.djangoproject.com/browser/django/trunk/django/forms/forms.py#L376
     44        # and therefore this id gets prefixed with 'id_' which breaks the form fields
     45        # expected name when used in a formset
     46       
     47        # so, an ugly hack therefore to strip the prefix here...
     48        self.params['id'] = self.params['id'].lstrip('id_') #.replace('-','_')
     49       
    4150        # Constructing the JavaScript module name using the ID of
    4251        # the GeometryField (passed in via the `attrs` keyword).
    43         self.params['module'] = 'geodjango_%s' % self.params['field_name']
     52        # javascript functions can't handle '-' so switch them out
     53        self.params['module'] = self.params['id'].replace('-','_')
     54        #self.params['module'] = 'geodjango_%s' % (self.params['field_name'])
    4455
    4556        if value:
    4657            # Transforming the geometry to the projection used on the
  • django/contrib/gis/templates/gis/admin/openlayers.html

     
    3232<div id="{{ id }}_map"{% if LANGUAGE_BIDI %} dir="ltr"{% endif %}></div>
    3333<a href="javascript:{{ module }}.clearFeatures()">Delete all Features</a>
    3434{% if display_wkt %}<p> WKT debugging window:</p>{% endif %}
    35 <textarea id="{{ id }}" class="vWKTField required" cols="150" rows="10" name="{{ field_name }}">{{ wkt }}</textarea>
     35<textarea id="{{ id }}" class="vWKTField required" cols="150" rows="10" name="{{ id }}">{{ wkt }}</textarea>
    3636<script type="text/javascript">{% block init_function %}{{ module }}.init();{% endblock %}</script>
    3737</span>
  • django/contrib/gis/templates/gis/admin/openlayers.js

     
    107107    {{ module }}.map.addLayer({{ module }}.layers.base);
    108108    {% block extra_layers %}{% endblock %}
    109109    {% if is_linestring %}OpenLayers.Feature.Vector.style["default"]["strokeWidth"] = 3; // Default too thin for linestrings. {% endif %}
    110     {{ module }}.layers.vector = new OpenLayers.Layer.Vector(" {{ field_name }}");
     110    {{ module }}.layers.vector = new OpenLayers.Layer.Vector("{{ module }}_vectors");
    111111    {{ module }}.map.addLayer({{ module }}.layers.vector);
    112112    // Read WKT from the text field.
    113113    var wkt = document.getElementById('{{ id }}').value;
Back to Top