Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.0.X] Fixed #11216 and #11218 -- Corrected a few typos, thanks buriy.

Backport of [10861] from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10862 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0871c87b77f8e43bf3a8fd2d10b74f8a11ddfef9 1 parent e2e092c
Gary Wilson Jr. authored May 29, 2009
56  django/contrib/gis/utils/ogrinspect.py
@@ -12,12 +12,12 @@
12 12
 
13 13
 def mapping(data_source, geom_name='geom', layer_key=0, multi_geom=False):
14 14
     """
15  
-    Given a DataSource, generates a dictionary that may be used 
  15
+    Given a DataSource, generates a dictionary that may be used
16 16
     for invoking the LayerMapping utility.
17 17
 
18 18
     Keyword Arguments:
19 19
      `geom_name` => The name of the geometry field to use for the model.
20  
-     
  20
+
21 21
      `layer_key` => The key for specifying which layer in the DataSource to use;
22 22
        defaults to 0 (the first layer).  May be an integer index or a string
23 23
        identifier for the layer.
@@ -31,7 +31,7 @@ def mapping(data_source, geom_name='geom', layer_key=0, multi_geom=False):
31 31
         pass
32 32
     else:
33 33
         raise TypeError('Data source parameter must be a string or a DataSource object.')
34  
-    
  34
+
35 35
     # Creating the dictionary.
36 36
     _mapping = {}
37 37
 
@@ -52,32 +52,32 @@ def ogrinspect(*args, **kwargs):
52 52
     model name this function will generate a GeoDjango model.
53 53
 
54 54
     Usage:
55  
-    
  55
+
56 56
     >>> from django.contrib.gis.utils import ogrinspect
57 57
     >>> ogrinspect('/path/to/shapefile.shp','NewModel')
58  
-    
  58
+
59 59
     ...will print model definition to stout
60  
-    
  60
+
61 61
     or put this in a python script and use to redirect the output to a new
62 62
     model like:
63  
-    
  63
+
64 64
     $ python generate_model.py > myapp/models.py
65  
-    
66  
-    # generate_model.py 
  65
+
  66
+    # generate_model.py
67 67
     from django.contrib.gis.utils import ogrinspect
68 68
     shp_file = 'data/mapping_hacks/world_borders.shp'
69 69
     model_name = 'WorldBorders'
70 70
 
71 71
     print ogrinspect(shp_file, model_name, multi_geom=True, srid=4326,
72 72
                      geom_name='shapes', blank=True)
73  
-                     
  73
+
74 74
     Required Arguments
75 75
      `datasource` => string or DataSource object to file pointer
76  
-     
  76
+
77 77
      `model name` => string of name of new model class to create
78  
-      
  78
+
79 79
     Optional Keyword Arguments
80  
-     `geom_name` => For specifying the model name for the Geometry Field. 
  80
+     `geom_name` => For specifying the model name for the Geometry Field.
81 81
        Otherwise will default to `geom`
82 82
 
83 83
      `layer_key` => The key for specifying which layer in the DataSource to use;
@@ -86,24 +86,24 @@ def ogrinspect(*args, **kwargs):
86 86
 
87 87
      `srid` => The SRID to use for the Geometry Field.  If it can be determined,
88 88
        the SRID of the datasource is used.
89  
-      
  89
+
90 90
      `multi_geom` => Boolean (default: False) - specify as multigeometry.
91  
-     
  91
+
92 92
      `name_field` => String - specifies a field name to return for the
93 93
        `__unicode__` function (which will be generated if specified).
94  
-     
95  
-     `imports` => Boolean (default: True) - set to False to omit the 
96  
-       `from django.contrib.gis.db import models` code from the 
  94
+
  95
+     `imports` => Boolean (default: True) - set to False to omit the
  96
+       `from django.contrib.gis.db import models` code from the
97 97
        autogenerated models thus avoiding duplicated imports when building
98 98
        more than one model by batching ogrinspect()
99  
-     
  99
+
100 100
      `decimal` => Boolean or sequence (default: False).  When set to True
101 101
        all generated model fields corresponding to the `OFTReal` type will
102 102
        be `DecimalField` instead of `FloatField`.  A sequence of specific
103 103
        field names to generate as `DecimalField` may also be used.
104 104
 
105 105
      `blank` => Boolean or sequence (default: False).  When set to True all
106  
-       generated model fields will have `blank=True`.  If the user wants to 
  106
+       generated model fields will have `blank=True`.  If the user wants to
107 107
        give specific fields to have blank, then a list/tuple of OGR field
108 108
        names may be used.
109 109
 
@@ -111,13 +111,13 @@ def ogrinspect(*args, **kwargs):
111 111
        model fields will have `null=True`.  If the user wants to specify
112 112
        give specific fields to have null, then a list/tuple of OGR field
113 113
        names may be used.
114  
-     
  114
+
115 115
     Note: This routine calls the _ogrinspect() helper to do the heavy lifting.
116 116
     """
117 117
     return '\n'.join(s for s in _ogrinspect(*args, **kwargs))
118 118
 
119 119
 def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=None,
120  
-                multi_geom=False, name_field=None, imports=True, 
  120
+                multi_geom=False, name_field=None, imports=True,
121 121
                 decimal=False, blank=False, null=False):
122 122
     """
123 123
     Helper routine for `ogrinspect` that generates GeoDjango models corresponding
@@ -140,7 +140,7 @@ def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=Non
140 140
     # keyword arguments.
141 141
     def process_kwarg(kwarg):
142 142
         if isinstance(kwarg, (list, tuple)):
143  
-            return [s.lower() for s in kwarg] 
  143
+            return [s.lower() for s in kwarg]
144 144
         elif kwarg:
145 145
             return [s.lower() for s in ogr_fields]
146 146
         else:
@@ -164,18 +164,18 @@ def get_kwargs_str(field_name):
164 164
         yield ''
165 165
 
166 166
     yield 'class %s(models.Model):' % model_name
167  
-    
  167
+
168 168
     for field_name, width, precision, field_type in izip(ogr_fields, layer.field_widths, layer.field_precisions, layer.field_types):
169 169
         # The model field name.
170 170
         mfield = field_name.lower()
171 171
         if mfield[-1:] == '_': mfield += 'field'
172  
-        
  172
+
173 173
         # Getting the keyword args string.
174 174
         kwargs_str = get_kwargs_str(field_name)
175 175
 
176 176
         if field_type is OFTReal:
177 177
             # By default OFTReals are mapped to `FloatField`, however, they
178  
-            # may also be mapped to `DecimalField` if specified in the 
  178
+            # may also be mapped to `DecimalField` if specified in the
179 179
             # `decimal` keyword.
180 180
             if field_name.lower() in decimal_fields:
181 181
                 yield '    %s = models.DecimalField(max_digits=%d, decimal_places=%d%s)' % (mfield, width, precision, kwargs_str)
@@ -192,8 +192,8 @@ def get_kwargs_str(field_name):
192 192
         elif field_type is OFTDate:
193 193
             yield '    %s = models.TimeField(%s)' % (mfield, kwargs_str[2:])
194 194
         else:
195  
-            raise TypeError('Unknown field type %s in %s' % (fld_type, mfield))
196  
-    
  195
+            raise TypeError('Unknown field type %s in %s' % (field_type, mfield))
  196
+
197 197
     # TODO: Autodetection of multigeometry types (see #7218).
198 198
     gtype = layer.geom_type
199 199
     if multi_geom and gtype.num in (1, 2, 3):
4  django/db/models/sql/query.py
@@ -425,7 +425,7 @@ def get_columns(self, with_aliases=False):
425 425
 
426 426
         If 'with_aliases' is true, any column names that are duplicated
427 427
         (without the table names) are given unique aliases. This is needed in
428  
-        some cases to avoid ambiguitity with nested queries.
  428
+        some cases to avoid ambiguity with nested queries.
429 429
         """
430 430
         qn = self.quote_name_unless_alias
431 431
         qn2 = self.connection.ops.quote_name
@@ -1823,7 +1823,7 @@ def execute_sql(self, result_type=MULTI):
1823 1823
             return cursor
1824 1824
         if result_type == SINGLE:
1825 1825
             if self.ordering_aliases:
1826  
-                return cursor.fetchone()[:-len(results.ordering_aliases)]
  1826
+                return cursor.fetchone()[:-len(self.ordering_aliases)]
1827 1827
             return cursor.fetchone()
1828 1828
 
1829 1829
         # The MULTI case.

0 notes on commit 0871c87

Please sign in to comment.
Something went wrong with that request. Please try again.