Author: Alex
Date: 2009-11-23 10:43:17 -0600 (Mon, 23 Nov 2009)
New Revision: 11766

Modified:
   django/branches/soc2009/multidb/TODO
   django/branches/soc2009/multidb/django/contrib/sessions/backends/db.py
   django/branches/soc2009/multidb/docs/ref/settings.txt
Log:
[soc2009/multidb] Updated db-backed session to be multi-db compatible.  Patch 
from Russell Keith-Magee.

Modified: django/branches/soc2009/multidb/TODO
===================================================================
--- django/branches/soc2009/multidb/TODO        2009-11-23 16:43:06 UTC (rev 
11765)
+++ django/branches/soc2009/multidb/TODO        2009-11-23 16:43:17 UTC (rev 
11766)
@@ -7,12 +7,13 @@
  * Finalize the sql.Query internals
    * Clean up the use of db.backend.query_class()
    * Verify it still works with GeoDjango
- * Resolve internal uses of multidb interface
-   * Update database backend for session store to use Multidb
-   * Check default Site creation behavior
  * Resolve the public facing UI issues around using multi-db
    * Should we take the opportunity to modify DB backends to use fully 
qualified paths?
+   * Should we clean up DATABASES['DATABASE_NAME'] to DATABASES['NAME'] etc?
    * Meta.using? Is is still required/desirable?
+ * Fix the regressiontests/multiple_database test failures
+    * Give instances knowledge of the database from which they were loaded.
+    * Cascade instance using to m2m queries
  * Cleanup of new API entry points
     * validate() on a field
         * name/purpose clash with Honza?

Modified: django/branches/soc2009/multidb/django/contrib/sessions/backends/db.py
===================================================================
--- django/branches/soc2009/multidb/django/contrib/sessions/backends/db.py      
2009-11-23 16:43:06 UTC (rev 11765)
+++ django/branches/soc2009/multidb/django/contrib/sessions/backends/db.py      
2009-11-23 16:43:17 UTC (rev 11766)
@@ -1,4 +1,5 @@
 import datetime
+from django.conf import settings
 from django.contrib.sessions.models import Session
 from django.contrib.sessions.backends.base import SessionBase, CreateError
 from django.core.exceptions import SuspiciousOperation
@@ -9,6 +10,10 @@
     """
     Implements database session store.
     """
+    def __init__(self, session_key=None):
+        self.using = getattr(settings, "SESSION_DB_ALIAS", DEFAULT_DB_ALIAS)
+        super(SessionStore, self).__init__(session_key)
+
     def load(self):
         try:
             s = Session.objects.get(
@@ -54,12 +59,12 @@
             expire_date = self.get_expiry_date()
         )
         # TODO update for multidb
-        sid = transaction.savepoint(using=DEFAULT_DB_ALIAS)
+        sid = transaction.savepoint(using=self.using)
         try:
             obj.save(force_insert=must_create)
         except IntegrityError:
             if must_create:
-                transaction.savepoint_rollback(sid, using=DEFAULT_DB_ALIAS)
+                transaction.savepoint_rollback(sid, using=self.using)
                 raise CreateError
             raise
 

Modified: django/branches/soc2009/multidb/docs/ref/settings.txt
===================================================================
--- django/branches/soc2009/multidb/docs/ref/settings.txt       2009-11-23 
16:43:06 UTC (rev 11765)
+++ django/branches/soc2009/multidb/docs/ref/settings.txt       2009-11-23 
16:43:17 UTC (rev 11766)
@@ -1056,6 +1056,18 @@
 
 .. setting:: SESSION_EXPIRE_AT_BROWSER_CLOSE
 
+SESSION_DB_ALIAS
+----------------
+
+.. versionadded:: 1.2
+
+Default: ``None``
+
+If you're using database-backed session storage, this selects the database
+alias that will be used to store session data. By default, Django will use
+the ``default`` database, but you can store session data on any database
+you choose.
+
 SESSION_EXPIRE_AT_BROWSER_CLOSE
 -------------------------------
 

--

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=.


Reply via email to