Ticket #10411: update_fix.diff
File update_fix.diff, 6.3 KB (added by , 16 years ago) |
---|
-
django/contrib/gis/db/models/sql/__init__.py
1 1 from django.contrib.gis.db.models.sql.conversion import AreaField, DistanceField, GeomField 2 from django.contrib.gis.db.models.sql.query import GeoQuery 2 from django.contrib.gis.db.models.sql.query import GeoQuery, GeoUpdateQuery 3 3 from django.contrib.gis.db.models.sql.where import GeoWhereNode -
django/contrib/gis/db/models/sql/query.py
306 306 # Otherwise, check by the given field name -- which may be 307 307 # a lookup to a _related_ geographic field. 308 308 return GeoWhereNode._check_geo_field(self.model._meta, field_name) 309 310 class GeoUpdateQuery(sql.subqueries.UpdateQuery): 311 312 def add_update_fields(self, values_seq): 313 """ 314 Overloaded so that get_db_prep_save() is called on values 315 before going to `add_update_fields`. 316 """ 317 for i, row in enumerate(values_seq): 318 fld, model, val = row 319 if isinstance(fld, GeometryField): 320 values_seq[i] = (fld, model, fld.get_db_prep_save(val)) 321 return super(GeoUpdateQuery, self).add_update_fields(values_seq) -
django/contrib/gis/db/models/query.py
1 1 from django.core.exceptions import ImproperlyConfigured 2 from django.db import connection 2 from django.db import connection, transaction 3 3 from django.db.models.query import sql, QuerySet, Q 4 4 5 5 from django.contrib.gis.db.backend import SpatialBackend 6 6 from django.contrib.gis.db.models import aggregates 7 7 from django.contrib.gis.db.models.fields import GeometryField, PointField 8 from django.contrib.gis.db.models.sql import AreaField, DistanceField, GeomField, GeoQuery, Geo WhereNode8 from django.contrib.gis.db.models.sql import AreaField, DistanceField, GeomField, GeoQuery, GeoUpdateQuery, GeoWhereNode 9 9 from django.contrib.gis.measure import Area, Distance 10 10 from django.contrib.gis.models import get_srid_info 11 11 … … 28 28 super(GeoQuerySet, self).__init__(model=model, query=query) 29 29 self.query = query or GeoQuery(self.model, connection) 30 30 31 #### Overloaded methods #### 32 def update(self, **kwargs): 33 """ 34 Updates all elements in the current QuerySet, setting all the given 35 fields to the appropriate values. 36 37 Overloaded to use GeoUpdateQuery instead of UpdateQuery. 38 """ 39 assert self.query.can_filter(), \ 40 "Cannot update a query once a slice has been taken." 41 query = self.query.clone(GeoUpdateQuery) 42 query.add_update_values(kwargs) 43 rows = query.execute_sql(None) 44 transaction.commit_unless_managed() 45 self._result_cache = None 46 return rows 47 update.alters_data = True 48 49 #### Routines unique to GeoQuerySet #### 50 31 51 def area(self, tolerance=0.05, **kwargs): 32 52 """ 33 53 Returns the area of the geographic field in an `area` attribute on -
django/contrib/gis/db/backend/postgis/creation.py
140 140 # Closing the connection 141 141 connection.close() 142 142 settings.DATABASE_NAME = db_name 143 settings.DATABASE_SUPPORTS_TRANSACTIONS = connection.creation._rollback_works() 143 144 144 145 # Syncing the database 145 146 call_command('syncdb', verbosity=verbosity, interactive=interactive) -
django/contrib/gis/tests/geoapp/test_regress.py
1 import os, unittest 2 from django.test import TestCase 3 from django.contrib.gis.db.backend import SpatialBackend 4 from django.contrib.gis.tests.utils import no_mysql, no_oracle, no_postgis 5 from models import City 6 7 class GeoRegressionTests(TestCase): 8 9 def test01_update(self): 10 "Testing GeoQuerySet.update(), see #10411." 11 pnt = City.objects.get(name='Pueblo').point 12 bak = pnt.clone() 13 pnt.y += 0.005 14 15 City.objects.filter(name='Pueblo').update(point=pnt) 16 self.assertEqual(pnt, City.objects.get(name='Pueblo').point) 17 City.objects.filter(name='Pueblo').update(point=bak) 18 self.assertEqual(bak, City.objects.get(name='Pueblo').point) 19 20 -
django/contrib/gis/tests/geoapp/tests.py
571 571 for pc in qs: self.assertEqual(32128, pc.point.srid) 572 572 573 573 from test_feeds import GeoFeedTest 574 from test_regress import GeoRegressionTests 574 575 from test_sitemaps import GeoSitemapTest 576 575 577 def suite(): 576 578 s = unittest.TestSuite() 579 s.addTest(unittest.makeSuite(GeoRegressionTests)) 577 580 s.addTest(unittest.makeSuite(GeoModelTest)) 578 581 s.addTest(unittest.makeSuite(GeoFeedTest)) 579 582 s.addTest(unittest.makeSuite(GeoSitemapTest)) -
django/contrib/gis/tests/geoapp/tests_mysql.py
174 174 self.assertRaises(ImproperlyConfigured, Country.objects.all().gml, field_name='mpoly') 175 175 176 176 from test_feeds import GeoFeedTest 177 from test_regress import GeoRegressionTests 177 178 from test_sitemaps import GeoSitemapTest 179 178 180 def suite(): 179 181 s = unittest.TestSuite() 182 s.addTest(unittest.makeSuite(GeoRegressionTests)) 180 183 s.addTest(unittest.makeSuite(GeoModelTest)) 181 184 s.addTest(unittest.makeSuite(GeoFeedTest)) 182 185 s.addTest(unittest.makeSuite(GeoSitemapTest))