Ticket #9806: 9806.2.diff
File 9806.2.diff, 5.5 KB (added by , 16 years ago) |
---|
-
django/contrib/gis/admin/options.py
diff --git a/django/contrib/gis/admin/options.py b/django/contrib/gis/admin/options.py index 71fb87b..07cd88c 100644
a b class GeoModelAdmin(ModelAdmin): 66 66 in the `widget` attribute) using the settings from the attributes set 67 67 in this class. 68 68 """ 69 is_collection = db_field._geom in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION') 70 if is_collection: 71 if db_field._geom == 'GEOMETRYCOLLECTION': collection_type = 'Any' 72 else: collection_type = OGRGeomType(db_field._geom.replace('MULTI', '')) 69 is_unknown = db_field._geom in ('GEOMETRY',) 70 if not is_unknown: 71 #If it is not generic, get the parameters from the db_field 72 is_collection = db_field._geom in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION') 73 if is_collection: 74 if db_field._geom == 'GEOMETRYCOLLECTION': collection_type = 'Any' 75 else: collection_type = OGRGeomType(db_field._geom.replace('MULTI', '')) 76 else: 77 collection_type = 'None' 78 is_linestring = db_field._geom in ('LINESTRING', 'MULTILINESTRING') 79 is_polygon = db_field._geom in ('POLYGON', 'MULTIPOLYGON') 80 is_point = db_field._geom in ('POINT', 'MULTIPOINT') 81 geom_type = OGRGeomType(db_field._geom) 73 82 else: 83 #If it is generic, set sensible defaults 84 is_collection = False 74 85 collection_type = 'None' 86 is_linestring = False 87 is_polygon = False 88 is_point = False 89 geom_type = OGRGeomType('Unknown') 75 90 76 91 class OLMap(self.widget): 77 92 template = self.map_template … … class GeoModelAdmin(ModelAdmin): 81 96 'default_lat' : self.default_lat, 82 97 'default_zoom' : self.default_zoom, 83 98 'display_wkt' : self.debug or self.display_wkt, 84 'geom_type' : OGRGeomType(db_field._geom),99 'geom_type' : geom_type, 85 100 'field_name' : db_field.name, 101 'is_unknown': is_unknown, 86 102 'is_collection' : is_collection, 87 103 'scrollable' : self.scrollable, 88 104 'layerswitcher' : self.layerswitcher, 89 105 'collection_type' : collection_type, 90 'is_linestring' : db_field._geom in ('LINESTRING', 'MULTILINESTRING'),91 'is_polygon' : db_field._geom in ('POLYGON', 'MULTIPOLYGON'),92 'is_point' : db_field._geom in ('POINT', 'MULTIPOINT'),106 'is_linestring' : is_linestring, 107 'is_polygon' : is_polygon, 108 'is_point' : is_point, 93 109 'num_zoom' : self.num_zoom, 94 110 'max_zoom' : self.max_zoom, 95 111 'min_zoom' : self.min_zoom, -
django/contrib/gis/admin/widgets.py
diff --git a/django/contrib/gis/admin/widgets.py b/django/contrib/gis/admin/widgets.py index 27abc8f..9732efa 100644
a b from django.contrib.gis.gdal import OGRException 2 2 from django.contrib.gis.geos import GEOSGeometry, GEOSException 3 3 from django.forms.widgets import Textarea 4 4 from django.template.loader import render_to_string 5 5 from django.contrib.gis.gdal import OGRGeomType 6 6 class OpenLayersWidget(Textarea): 7 7 """ 8 8 Renders an OpenLayers map using the WKT of the geometry. … … class OpenLayersWidget(Textarea): 23 23 value = GEOSGeometry(value) 24 24 except (GEOSException, ValueError): 25 25 value = None 26 27 if value and value.geom_type.upper() != self.geom_type: 26 if value and value.geom_type.upper() != self.geom_type and self.geom_type != 'GEOMETRY': 28 27 value = None 29 28 30 29 # Constructing the dictionary of the map options. … … class OpenLayersWidget(Textarea): 51 50 # geometry. 52 51 self.params['wkt'] = wkt 53 52 53 # Check if the field is generic so the proper values are overriden 54 if self.params['is_unknown']: 55 self.params['geom_type'] = OGRGeomType(value.geom_type) 56 if value.geom_type.upper() == 'LINESTRING': 57 self.params['is_linestring'] = True 58 elif value.geom_type.upper() == 'POLYGON': 59 self.params['is_polygon'] = True 60 elif value.geom_type.upper() == 'POINT': 61 self.params['is_polygon'] = True 62 elif value.geom_type.upper() in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION'): 63 self.params['is_collection']=True 64 if value.geom_type.upper() == 'GEOMETRYCOLLECTION': self.params['collection_type'] = 'Any' 65 else: self.params['collection_type'] = OGRGeomType(db_field._geom.replace('MULTI', '')) 66 else: 67 if self.params['is_unknown']: 68 # If the geometry is unknown and the value is not set, make it as flexible as possible. 69 self.params['geom_type'] = OGRGeomType('GEOMETRYCOLLECTION') 70 self.params['is_collection']=True 71 self.params['collection_type'] = 'Any' 54 72 return render_to_string(self.template, self.params) 55 73 56 74 def map_options(self):