Author: Alex
Date: 2009-12-17 10:13:07 -0600 (Thu, 17 Dec 2009)
New Revision: 11893
Modified:
django/branches/soc2009/multidb/django/contrib/auth/models.py
django/branches/soc2009/multidb/django/contrib/gis/sitemaps/views.py
django/branches/soc2009/multidb/django/contrib/gis/utils/layermapping.py
django/branches/soc2009/multidb/django/db/models/query.py
django/branches/soc2009/multidb/tests/modeltests/fixtures/models.py
django/branches/soc2009/multidb/tests/regressiontests/fixtures_regress/models.py
django/branches/soc2009/multidb/tests/regressiontests/generic_inline_admin/tests.py
django/branches/soc2009/multidb/tests/regressiontests/multiple_database/models.py
Log:
[soc2009/multidb] Modified using= arguments to default to None; modified
querysets so you can track explicit database assignments. Patch from Russell
Keith-Magee.
Modified: django/branches/soc2009/multidb/django/contrib/auth/models.py
===================================================================
--- django/branches/soc2009/multidb/django/contrib/auth/models.py
2009-12-17 16:12:51 UTC (rev 11892)
+++ django/branches/soc2009/multidb/django/contrib/auth/models.py
2009-12-17 16:13:07 UTC (rev 11893)
@@ -48,7 +48,7 @@
pass
class PermissionManager(models.Manager):
- def get_by_natural_key(self, codename, app_label, model,
using=DEFAULT_DB_ALIAS):
+ def get_by_natural_key(self, codename, app_label, model, using=None):
return self.using(using).get(
codename=codename,
content_type=ContentType.objects.get_by_natural_key(app_label,
model)
@@ -106,7 +106,7 @@
return self.name
class UserManager(models.Manager):
- def create_user(self, username, email, password=None,
using=DEFAULT_DB_ALIAS):
+ def create_user(self, username, email, password=None, using=None):
"Creates and saves a User with the given username, e-mail and
password."
now = datetime.datetime.now()
user = self.model(None, username, '', '', email.strip().lower(),
'placeholder', False, True, False, now, now)
@@ -117,7 +117,7 @@
user.save(using=using)
return user
- def create_superuser(self, username, email, password,
using=DEFAULT_DB_ALIAS):
+ def create_superuser(self, username, email, password, using=None):
u = self.create_user(username, email, password)
u.is_staff = True
u.is_active = True
Modified: django/branches/soc2009/multidb/django/contrib/gis/sitemaps/views.py
===================================================================
--- django/branches/soc2009/multidb/django/contrib/gis/sitemaps/views.py
2009-12-17 16:12:51 UTC (rev 11892)
+++ django/branches/soc2009/multidb/django/contrib/gis/sitemaps/views.py
2009-12-17 16:13:07 UTC (rev 11893)
@@ -59,7 +59,7 @@
xml = smart_str(loader.render_to_string('gis/sitemaps/geo_sitemap.xml',
{'urlset': urls}))
return HttpResponse(xml, mimetype='application/xml')
-def kml(request, label, model, field_name=None, compress=False,
using=DEFAULT_DB_ALIAS):
+def kml(request, label, model, field_name=None, compress=False, using=None):
"""
This view generates KML for the given app label, model, and field name.
@@ -83,15 +83,15 @@
if connection.ops.postgis:
# PostGIS will take care of transformation.
- placemarks = klass._default_manager.kml(field_name=field_name)
+ placemarks =
klass._default_manager.using(using).kml(field_name=field_name)
else:
# There's no KML method on Oracle or MySQL, so we use the `kml`
# attribute of the lazy geometry instead.
placemarks = []
if connection.ops.oracle:
- qs = klass._default_manager.transform(4326, field_name=field_name)
+ qs = klass._default_manager.using(using).transform(4326,
field_name=field_name)
else:
- qs = klass._default_manager.all()
+ qs = klass._default_manager.using(using).all()
for mod in qs:
setattr(mod, 'kml', getattr(mod, field_name).kml)
placemarks.append(mod)
@@ -103,7 +103,7 @@
render = render_to_kml
return render('gis/kml/placemarks.kml', {'places' : placemarks})
-def kmz(request, label, model, field_name=None, using=DEFAULT_DB_ALIAS):
+def kmz(request, label, model, field_name=None, using=None):
"""
This view returns KMZ for the given app label, model, and field name.
"""
Modified:
django/branches/soc2009/multidb/django/contrib/gis/utils/layermapping.py
===================================================================
--- django/branches/soc2009/multidb/django/contrib/gis/utils/layermapping.py
2009-12-17 16:12:51 UTC (rev 11892)
+++ django/branches/soc2009/multidb/django/contrib/gis/utils/layermapping.py
2009-12-17 16:13:07 UTC (rev 11893)
@@ -67,7 +67,7 @@
def __init__(self, model, data, mapping, layer=0,
source_srs=None, encoding=None,
transaction_mode='commit_on_success',
- transform=True, unique=None, using=DEFAULT_DB_ALIAS):
+ transform=True, unique=None, using=None):
"""
A LayerMapping object is initialized using the given Model (not an
instance),
a DataSource (or string path to an OGR-supported data file), and a
mapping
Modified: django/branches/soc2009/multidb/django/db/models/query.py
===================================================================
--- django/branches/soc2009/multidb/django/db/models/query.py 2009-12-17
16:12:51 UTC (rev 11892)
+++ django/branches/soc2009/multidb/django/db/models/query.py 2009-12-17
16:13:07 UTC (rev 11893)
@@ -28,7 +28,7 @@
def __init__(self, model=None, query=None, using=None):
self.model = model
# EmptyQuerySet instantiates QuerySet with model as None
- self.db = using or DEFAULT_DB_ALIAS
+ self._db = using
self.query = query or sql.Query(self.model)
self._result_cache = None
self._iter = None
@@ -688,7 +688,7 @@
Selects which database this QuerySet should excecute it's query
against.
"""
clone = self._clone()
- clone.db = alias
+ clone._db = alias
return clone
###################################
@@ -708,6 +708,11 @@
return False
ordered = property(ordered)
+ def db(self):
+ "Return the database that will be used if this query is executed now"
+ return self._db or DEFAULT_DB_ALIAS
+ db = property(db)
+
###################
# PRIVATE METHODS #
###################
@@ -719,7 +724,7 @@
if self._sticky_filter:
query.filter_is_sticky = True
c = klass(model=self.model, query=query)
- c.db = self.db
+ c._db = self._db
c.__dict__.update(kwargs)
if setup and hasattr(c, '_setup_query'):
c._setup_query()
Modified: django/branches/soc2009/multidb/tests/modeltests/fixtures/models.py
===================================================================
--- django/branches/soc2009/multidb/tests/modeltests/fixtures/models.py
2009-12-17 16:12:51 UTC (rev 11892)
+++ django/branches/soc2009/multidb/tests/modeltests/fixtures/models.py
2009-12-17 16:13:07 UTC (rev 11893)
@@ -57,7 +57,7 @@
self.tagged, self.name)
class PersonManager(models.Manager):
- def get_by_natural_key(self, name, using=DEFAULT_DB_ALIAS):
+ def get_by_natural_key(self, name, using=None):
return self.using(using).get(name=name)
class Person(models.Model):
Modified:
django/branches/soc2009/multidb/tests/regressiontests/fixtures_regress/models.py
===================================================================
---
django/branches/soc2009/multidb/tests/regressiontests/fixtures_regress/models.py
2009-12-17 16:12:51 UTC (rev 11892)
+++
django/branches/soc2009/multidb/tests/regressiontests/fixtures_regress/models.py
2009-12-17 16:13:07 UTC (rev 11893)
@@ -83,7 +83,7 @@
# Check for forward references in FKs and M2Ms with natural keys
class TestManager(models.Manager):
- def get_by_natural_key(self, key, using=DEFAULT_DB_ALIAS):
+ def get_by_natural_key(self, key, using=None):
return self.using(using).get(name=key)
class Store(models.Model):
Modified:
django/branches/soc2009/multidb/tests/regressiontests/generic_inline_admin/tests.py
===================================================================
---
django/branches/soc2009/multidb/tests/regressiontests/generic_inline_admin/tests.py
2009-12-17 16:12:51 UTC (rev 11892)
+++
django/branches/soc2009/multidb/tests/regressiontests/generic_inline_admin/tests.py
2009-12-17 16:13:07 UTC (rev 11893)
@@ -107,7 +107,6 @@
self.assertEquals(formset.forms[0].as_p(), '<p><label
for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label>
<input id="id_generic_inline_admin-media-content_type-object_id-0-url"
type="text" name="generic_inline_admin-media-content_type-object_id-0-url"
value="http://example.com/logo.png" maxlength="200" /><input type="hidden"
name="generic_inline_admin-media-content_type-object_id-0-id" value="2"
id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>')
self.assertEquals(formset.forms[1].as_p(), '<p><label
for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label>
<input id="id_generic_inline_admin-media-content_type-object_id-1-url"
type="text" name="generic_inline_admin-media-content_type-object_id-1-url"
maxlength="200" /><input type="hidden"
name="generic_inline_admin-media-content_type-object_id-1-id"
id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>')
-
def testGenericInlineFormsetFactory(self):
# Regression test for #10522.
inline_formset = generic_inlineformset_factory(Media,
Modified:
django/branches/soc2009/multidb/tests/regressiontests/multiple_database/models.py
===================================================================
---
django/branches/soc2009/multidb/tests/regressiontests/multiple_database/models.py
2009-12-17 16:12:51 UTC (rev 11892)
+++
django/branches/soc2009/multidb/tests/regressiontests/multiple_database/models.py
2009-12-17 16:13:07 UTC (rev 11893)
@@ -17,7 +17,7 @@
ordering = ('source',)
class PersonManager(models.Manager):
- def get_by_natural_key(self, name, using=DEFAULT_DB_ALIAS):
+ def get_by_natural_key(self, name, using=None):
return self.using(using).get(name=name)
class Person(models.Model):
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.