Commit 35f934f5 authored by Malcolm Tredinnick's avatar Malcolm Tredinnick
Browse files

Pass values through get_db_prep_save() in a QuerySet.update() call.

This removes a long-standing FIXME in the update() handling and allows for
greater flexibility in the values passed in. In particular, it brings updates
into line with saves for django.contrib.gis fields, so fixed #10411.

Thanks to Justin Bronn and Russell Keith-Magee for help with this patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10003 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent cee31735
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -12,3 +12,6 @@ class WKTAdaptor(object):

    def __str__(self):
        return self.wkt

    def prepare_database_save(self, unused):
        return self
+3 −0
Original line number Diff line number Diff line
@@ -31,3 +31,6 @@ class PostGISAdaptor(object):
        "Returns a properly quoted string for use in PostgreSQL/PostGIS."
        # Want to use WKB, so wrap with psycopg2 Binary() to quote properly.
        return "%s(%s, %s)" % (GEOM_FROM_WKB, Binary(self.wkb), self.srid or -1)

    def prepare_database_save(self, unused):
        return self
+18 −0
Original line number Diff line number Diff line
import os, unittest
from django.contrib.gis.db.backend import SpatialBackend
from django.contrib.gis.tests.utils import no_mysql, no_oracle, no_postgis
from models import City

class GeoRegressionTests(unittest.TestCase):

    def test01_update(self):
        "Testing GeoQuerySet.update(), see #10411."
        pnt = City.objects.get(name='Pueblo').point
        bak = pnt.clone()
        pnt.y += 0.005
        pnt.x += 0.005

        City.objects.filter(name='Pueblo').update(point=pnt)
        self.assertEqual(pnt, City.objects.get(name='Pueblo').point)
        City.objects.filter(name='Pueblo').update(point=bak)
        self.assertEqual(bak, City.objects.get(name='Pueblo').point)
+29 −26
Original line number Diff line number Diff line
@@ -204,8 +204,8 @@ class GeoModelTest(unittest.TestCase):
        self.assertRaises(TypeError, Country.objects.make_line)
        # Reference query:
        # SELECT AsText(ST_MakeLine(geoapp_city.point)) FROM geoapp_city;
        self.assertEqual(GEOSGeometry('LINESTRING(-95.363151 29.763374,-96.801611 32.782057,-97.521157 34.464642,174.783117 -41.315268,-104.609252 38.255001,-95.23506 38.971823,-87.650175 41.850385,-123.305196 48.462611)', srid=4326),
                         City.objects.make_line())
        ref_line = GEOSGeometry('LINESTRING(-95.363151 29.763374,-96.801611 32.782057,-97.521157 34.464642,174.783117 -41.315268,-104.609252 38.255001,-95.23506 38.971823,-87.650175 41.850385,-123.305196 48.462611)', srid=4326)
        self.assertEqual(ref_line, City.objects.make_line())

    def test09_disjoint(self):
        "Testing the `disjoint` lookup type."
@@ -571,10 +571,13 @@ class GeoModelTest(unittest.TestCase):
        for pc in qs: self.assertEqual(32128, pc.point.srid)

from test_feeds import GeoFeedTest
from test_regress import GeoRegressionTests
from test_sitemaps import GeoSitemapTest

def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(GeoModelTest))
    s.addTest(unittest.makeSuite(GeoFeedTest))
    s.addTest(unittest.makeSuite(GeoSitemapTest))
    s.addTest(unittest.makeSuite(GeoRegressionTests))
    return s
+10 −7
Original line number Diff line number Diff line
@@ -174,10 +174,13 @@ class GeoModelTest(unittest.TestCase):
        self.assertRaises(ImproperlyConfigured, Country.objects.all().gml, field_name='mpoly')

from test_feeds import GeoFeedTest
from test_regress import GeoRegressionTests
from test_sitemaps import GeoSitemapTest

def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(GeoModelTest))
    s.addTest(unittest.makeSuite(GeoFeedTest))
    s.addTest(unittest.makeSuite(GeoSitemapTest))
    s.addTest(unittest.makeSuite(GeoRegressionTests))
    return s
Loading