Ticket #11810: 11810-r12932.diff

File 11810-r12932.diff, 6.3 KB (added by Ramiro Morales, 15 years ago)

Justin's patch modified to additionally tests if the field is in the new 1.2 readonly_fields ModelAdmin? option

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

    diff -r bf6f4f1df989 django/contrib/gis/admin/options.py
    a b  
    6464    def get_map_widget(self, db_field):
    6565        """
    6666        Returns a subclass of the OpenLayersWidget (or whatever was specified
    67         in the `widget` attribute) using the settings from the attributes set 
     67        in the `widget` attribute) using the settings from the attributes set
    6868        in this class.
    6969        """
    7070        is_collection = db_field.geom_type in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION')
     
    9696                      'units' : self.units, #likely shoud get from object
    9797                      'max_resolution' : self.max_resolution,
    9898                      'max_extent' : self.max_extent,
    99                       'modifiable' : self.modifiable,
     99                      'modifiable' : self.modifiable or db_field.name not in self.readonly_fields,
    100100                      'mouse_position' : self.mouse_position,
    101101                      'scale_text' : self.scale_text,
    102102                      'map_width' : self.map_width,
     
    116116#      to your `spatial_ref_sys` table.  You'll need at least GDAL 1.5:
    117117#      >>> from django.contrib.gis.gdal import SpatialReference
    118118#      >>> from django.contrib.gis.utils import add_postgis_srs
    119 #      >>> add_postgis_srs(SpatialReference(900913)) # Adding the Google Projection 
     119#      >>> add_postgis_srs(SpatialReference(900913)) # Adding the Google Projection
    120120from django.contrib.gis import gdal
    121121if gdal.HAS_GDAL:
    122122    class OSMGeoAdmin(GeoModelAdmin):
  • django/contrib/gis/templates/gis/admin/openlayers.js

    diff -r bf6f4f1df989 django/contrib/gis/templates/gis/admin/openlayers.js
    a b  
    11{# Author: Justin Bronn, Travis Pinney & Dane Springmeyer #}
    22{% block vars %}var {{ module }} = {};
    3 {{ module }}.map = null; {{ module }}.controls = null; {{ module }}.panel = null; {{ module }}.re = new RegExp("^SRID=\d+;(.+)", "i"); {{ module }}.layers = {};
     3{{ module }}.map = null; {{ module }}.controls = null; {{ module }}.panel = null; {{ module }}.re = new RegExp("^SRID=\d+;(.+)", "i"); {{ module }}.layers = {};
     4{{ module }}.modifiable = {{ modifiable|yesno:"true,false" }};
    45{{ module }}.wkt_f = new OpenLayers.Format.WKT();
    56{{ module }}.is_collection = {{ is_collection|yesno:"true,false" }};
    67{{ module }}.collection_type = '{{ collection_type }}';
     
    4344{{ module }}.modify_wkt = function(event){
    4445  if ({{ module }}.is_collection){
    4546    if ({{ module }}.is_point){
    46       {{ module }}.add_wkt(event); 
     47      {{ module }}.add_wkt(event);
    4748      return;
    4849    } else {
    49       // When modifying the selected components are added to the 
     50      // When modifying the selected components are added to the
    5051      // vector layer so we only increment to the `num_geom` value.
    5152      var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}());
    5253      for (var i = 0; i < {{ module }}.num_geom; i++){
     
    6970  {{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }});
    7071}
    7172// Add Select control
    72 {{ module }}.addSelectControl = function(){   
     73{{ module }}.addSelectControl = function(){
    7374  var select = new OpenLayers.Control.SelectFeature({{ module }}.layers.vector, {'toggle' : true, 'clickout' : true});
    7475  {{ module }}.map.addControl(select);
    7576  select.activate();
     
    8889  } else if ({{ module }}.is_point){
    8990    draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'});
    9091  }
    91   {% if modifiable %}
    92   var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'});
    93   {{ module }}.controls = [nav, draw_ctl, mod];
    94   {% else %}
    95   {{ module }}.controls = [nav, darw_ctl];
    96   {% endif %} 
     92  if ({{ module }}.modifiable){
     93    var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'});
     94    {{ module }}.controls = [nav, draw_ctl, mod];
     95  } else {
     96    if(!lyr.features.length){
     97      {{ module }}.controls = [nav, draw_ctl];
     98    } else {
     99      {{ module }}.controls = [nav];
     100    }
     101  }
    97102}
    98103{{ module }}.init = function(){
    99104    {% block map_options %}// The options hash, w/ zoom, resolution, and projection settings.
    100     var options = { 
     105    var options = {
    101106{% autoescape off %}{% for item in map_options.items %}      '{{ item.0 }}' : {{ item.1 }}{% if not forloop.last %},{% endif %}
    102107{% endfor %}{% endautoescape %}    };{% endblock %}
    103108    // The admin map for this geometry field.
     
    112117    // Read WKT from the text field.
    113118    var wkt = document.getElementById('{{ id }}').value;
    114119    if (wkt){
    115       // After reading into geometry, immediately write back to 
     120      // After reading into geometry, immediately write back to
    116121      // WKT <textarea> as EWKT (so that SRID is included).
    117122      var admin_geom = {{ module }}.read_wkt(wkt);
    118123      {{ module }}.write_wkt(admin_geom);
     
    128133      // Zooming to the bounds.
    129134      {{ module }}.map.zoomToExtent(admin_geom.geometry.getBounds());
    130135      if ({{ module }}.is_point){
    131           {{ module }}.map.zoomTo({{ point_zoom }}); 
     136          {{ module }}.map.zoomTo({{ point_zoom }});
    132137      }
    133138    } else {
    134139      {{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }});
    135140    }
    136141    // This allows editing of the geographic fields -- the modified WKT is
    137142    // written back to the content field (as EWKT, so that the ORM will know
    138     // to transform back to original SRID). 
     143    // to transform back to original SRID).
    139144    {{ module }}.layers.vector.events.on({"featuremodified" : {{ module }}.modify_wkt});
    140145    {{ module }}.layers.vector.events.on({"featureadded" : {{ module }}.add_wkt});
    141146    {% block controls %}
     
    153158    {% if not scrollable %}{{ module }}.map.getControlsByClass('OpenLayers.Control.Navigation')[0].disableZoomWheel();{% endif %}
    154159    {% endblock %}
    155160    if (wkt){
    156       {{ module }}.enableEditing();
     161      if ({{ module }}.modifiable){
     162        {{ module }}.enableEditing();
     163      }
    157164    } else {
    158165      {{ module }}.enableDrawing();
    159166    }
Back to Top