Author: Alex
Date: 2009-12-17 10:13:25 -0600 (Thu, 17 Dec 2009)
New Revision: 11895

Modified:
   django/branches/soc2009/multidb/django/contrib/contenttypes/generic.py
   django/branches/soc2009/multidb/django/contrib/contenttypes/models.py
Log:
[soc2009/multidb] More cleanups of using= arguments.  Patch from Russell 
Keith-Magee.

Modified: django/branches/soc2009/multidb/django/contrib/contenttypes/generic.py
===================================================================
--- django/branches/soc2009/multidb/django/contrib/contenttypes/generic.py      
2009-12-17 16:13:17 UTC (rev 11894)
+++ django/branches/soc2009/multidb/django/contrib/contenttypes/generic.py      
2009-12-17 16:13:25 UTC (rev 11895)
@@ -45,7 +45,7 @@
             kwargs[self.ct_field] = self.get_content_type(obj=value)
             kwargs[self.fk_field] = value._get_pk_val()
 
-    def get_content_type(self, obj=None, id=None, using=DEFAULT_DB_ALIAS):
+    def get_content_type(self, obj=None, id=None, using=None):
         # Convenience function using get_model avoids a circular import when
         # using this model
         ContentType = get_model("contenttypes", "contenttype")

Modified: django/branches/soc2009/multidb/django/contrib/contenttypes/models.py
===================================================================
--- django/branches/soc2009/multidb/django/contrib/contenttypes/models.py       
2009-12-17 16:13:17 UTC (rev 11894)
+++ django/branches/soc2009/multidb/django/contrib/contenttypes/models.py       
2009-12-17 16:13:25 UTC (rev 11895)
@@ -8,52 +8,55 @@
     # This cache is shared by all the get_for_* methods.
     _cache = {}
 
-    def get_by_natural_key(self, app_label, model, using=DEFAULT_DB_ALIAS):
+    def get_by_natural_key(self, app_label, model, using=None):
+        db = using or DEFAULT_DB_ALIAS
         try:
-            ct = self.__class__._cache[using][(app_label, model)]
+            ct = self.__class__._cache[db][(app_label, model)]
         except KeyError:
-            ct = self.using(using).get(app_label=app_label, model=model)
+            ct = self.using(db).get(app_label=app_label, model=model)
         return ct
 
-    def get_for_model(self, model, using=DEFAULT_DB_ALIAS):
+    def get_for_model(self, model, using=None):
         """
         Returns the ContentType object for a given model, creating the
         ContentType if necessary. Lookups are cached so that subsequent lookups
         for the same model don't hit the database.
         """
+        db = using or DEFAULT_DB_ALIAS
         opts = model._meta
         while opts.proxy:
             model = opts.proxy_for_model
             opts = model._meta
         key = (opts.app_label, opts.object_name.lower())
         try:
-            ct = self.__class__._cache[using][key]
+            ct = self.__class__._cache[db][key]
         except KeyError:
             # Load or create the ContentType entry. The smart_unicode() is
             # needed around opts.verbose_name_raw because name_raw might be a
             # django.utils.functional.__proxy__ object.
-            ct, created = self.using(using).get_or_create(
+            ct, created = self.using(db).get_or_create(
                 app_label = opts.app_label,
                 model = opts.object_name.lower(),
                 defaults = {'name': smart_unicode(opts.verbose_name_raw)},
             )
-            self._add_to_cache(using, ct)
+            self._add_to_cache(db, ct)
 
         return ct
 
-    def get_for_id(self, id, using=DEFAULT_DB_ALIAS):
+    def get_for_id(self, id, using=None):
         """
         Lookup a ContentType by ID. Uses the same shared cache as get_for_model
         (though ContentTypes are obviously not created on-the-fly by 
get_by_id).
         """
+        db = using or DEFAULT_DB_ALIAS
         try:
-            ct = self.__class__._cache[using][id]
+            ct = self.__class__._cache[db][id]
 
         except KeyError:
             # This could raise a DoesNotExist; that's correct behavior and will
             # make sure that only correct ctypes get stored in the cache dict.
-            ct = self.using(using).get(pk=id)
-            self._add_to_cache(using, ct)
+            ct = self.using(db).get(pk=id)
+            self._add_to_cache(db, ct)
         return ct
 
     def clear_cache(self):

--

You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.


Reply via email to