Ticket #9806: 9806.3.diff
File 9806.3.diff, 5.6 KB (added by , 14 years ago) |
---|
-
django/contrib/gis/admin/options.py
67 67 in the `widget` attribute) using the settings from the attributes set 68 68 in this class. 69 69 """ 70 is_collection = db_field.geom_type in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION') 71 if is_collection: 72 if db_field.geom_type == 'GEOMETRYCOLLECTION': collection_type = 'Any' 73 else: collection_type = OGRGeomType(db_field.geom_type.replace('MULTI', '')) 70 71 is_unknown = db_field.geom_type in ('GEOMETRY',) 72 if not is_unknown: 73 #If it is not generic, get the parameters from the db_field 74 is_collection = db_field.geom_type in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION') 75 if is_collection: 76 if db_field.geom_type == 'GEOMETRYCOLLECTION': collection_type = 'Any' 77 else: collection_type = OGRGeomType(db_field.geom_type.upper().replace('MULTI', '')) 78 else: 79 collection_type = 'None' 80 is_linestring = db_field.geom_type in ('LINESTRING', 'MULTILINESTRING') 81 is_polygon = db_field.geom_type in ('POLYGON', 'MULTIPOLYGON') 82 is_point = db_field.geom_type in ('POINT', 'MULTIPOINT') 83 geom_type = OGRGeomType(db_field.geom_type) 74 84 else: 85 #If it is generic, set sensible defaults 86 is_collection = False 75 87 collection_type = 'None' 88 is_linestring = False 89 is_polygon = False 90 is_point = False 91 geom_type = OGRGeomType('Unknown') 76 92 77 93 class OLMap(self.widget): 78 94 template = self.map_template … … 81 97 'default_lat' : self.default_lat, 82 98 'default_zoom' : self.default_zoom, 83 99 'display_wkt' : self.debug or self.display_wkt, 84 'geom_type' : OGRGeomType(db_field.geom_type),100 'geom_type' : geom_type, 85 101 'field_name' : db_field.name, 102 'is_unknown': is_unknown, 86 103 'is_collection' : is_collection, 87 104 'scrollable' : self.scrollable, 88 105 'layerswitcher' : self.layerswitcher, 89 106 'collection_type' : collection_type, 90 'is_linestring' : db_field.geom_type in ('LINESTRING', 'MULTILINESTRING'),91 'is_polygon' : db_field.geom_type in ('POLYGON', 'MULTIPOLYGON'),92 'is_point' : db_field.geom_type in ('POINT', 'MULTIPOINT'),107 'is_linestring' : is_linestring, 108 'is_polygon' : is_polygon, 109 'is_point' : is_point, 93 110 'num_zoom' : self.num_zoom, 94 111 'max_zoom' : self.max_zoom, 95 112 'min_zoom' : self.min_zoom, -
django/contrib/gis/admin/widgets.py
4 4 from django.forms.widgets import Textarea 5 5 from django.template import loader, Context 6 6 from django.utils import translation 7 from django.contrib.gis.gdal import OGRGeomType 7 8 8 9 # Creating a template context that contains Django settings 9 10 # values needed by admin map templates. … … 31 32 value = GEOSGeometry(value) 32 33 except (GEOSException, ValueError): 33 34 value = None 34 35 if value and value.geom_type.upper() != self.geom_type: 35 if value and value.geom_type.upper() != self.geom_type and self.geom_type != 'GEOMETRY': 36 36 value = None 37 37 38 38 # Constructing the dictionary of the map options. … … 64 64 # Setting the parameter WKT with that of the transformed 65 65 # geometry. 66 66 self.params['wkt'] = wkt 67 67 68 # Check if the field is generic so the proper values are overriden 69 if self.params['is_unknown']: 70 self.params['geom_type'] = OGRGeomType(value.geom_type) 71 if value.geom_type.upper() == 'LINESTRING': 72 self.params['is_linestring'] = True 73 elif value.geom_type.upper() == 'POLYGON': 74 self.params['is_polygon'] = True 75 elif value.geom_type.upper() == 'POINT': 76 self.params['is_point'] = True 77 elif value.geom_type.upper() in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION'): 78 self.params['is_collection']=True 79 if value.geom_type.upper() == 'GEOMETRYCOLLECTION': 80 self.params['collection_type'] = 'Any' 81 else: 82 self.params['collection_type'] = OGRGeomType(value.geom_type.upper().replace('MULTI', '')) 83 84 else: 85 if self.params['is_unknown']: 86 # If the geometry is unknown and the value is not set, make it as flexible as possible. 87 self.params['geom_type'] = OGRGeomType('GEOMETRYCOLLECTION') 88 self.params['is_collection']=True 89 self.params['collection_type'] = 'Any' 90 68 91 return loader.render_to_string(self.template, self.params, 69 92 context_instance=geo_context) 70 93