Permalink
Browse files

Fixed an issue with preloading models for installed apps.

git-svn-id: http://tranquil.googlecode.com/svn/trunk@18 66ac46bf-b33b-0410-90a4-43c7d5e8004f
  • Loading branch information...
1 parent 2e1a131 commit 57fe11c37e508eab77b589b194d877c04ff5daf2 @davisp davisp committed Oct 7, 2007
Showing with 17 additions and 13 deletions.
  1. +9 −0 nose.cfg
  2. +1 −7 test/tranquil/model_tests.py
  3. +0 −2 tranquil/__init__.py
  4. +7 −4 tranquil/models.py
View
@@ -0,0 +1,9 @@
+# Make sure to add a .noserc to you home directory that looks like:
+#
+# [nosetests]
+# config=./nose.cfg
+#
+
+[nosetests]
+nocapture=True
+where=./test
@@ -1,18 +1,12 @@
-import cStringIO
import datetime
import os
import sys
import unittest
-sys.path.insert( 0, '/usr/local/src/tranquil/' )
+sys.path.insert( 0, os.path.dirname( __file__ ) + '../' )
os.environ['DJANGO_SETTINGS_MODULE'] = 'proj_name.settings'
-from django.core.management import execute_manager
-import proj_name.settings
-sys.argv = [ './manage.py', 'validate' ]
-execute_manager(proj_name.settings)
-
from tranquil import Session
from tranquil.models.app_name import Poll, Choice
from tranquil.translator import ORMObject
@@ -1,10 +1,8 @@
import re
-#from django.core.exceptions import ImproperlyConfigured
from sqlalchemy import create_engine, MetaData
from sqlalchemy.orm import sessionmaker
from tranquil.models import Importer
-
__all__ = ( 'engine', 'meta', 'Session', )
class EngineCache(object):
View
@@ -4,7 +4,7 @@
from django.conf import settings
from django.db.models import signals
-from django.db.models.loading import get_models
+from django.db.models.loading import get_apps, get_models
from django.dispatch import dispatcher
from django.utils.encoding import force_unicode
@@ -13,18 +13,21 @@
__all__ = ( '__path__', 'Importer' )
__path__ = 'tranquil.models'
-
class Importer(object):
def __init__(self,meta):
self.meta = meta
sys.meta_path.append( self )
self.apps = set()
- self.apps.add( getattr( settings, 'NO_MODEL_MODULE', DEFAULT_NO_MODEL ) )
self.cache = {}
self.trans = None
+ self.no_model = getattr( settings, 'NO_MODEL_MODULE', DEFAULT_NO_MODEL )
dispatcher.connect(self.cache_model,signal=signals.class_prepared)
def find_module(self,fullname,path=None):
+ if len( self.apps ) == 0:
+ get_models()
+ if not self.no_model in self.apps:
+ self.apps.add( self.no_model )
if fullname.startswith('tranquil.models.'):
app = fullname.replace( 'tranquil.models.', '' )
if app in self.apps:
@@ -50,5 +53,5 @@ def cache_model(self,sender=None):
if app not in self.apps:
self.apps.add( app )
table = sender._meta.db_table
- self.cache[table] = sender
+ self.cache[table] = sender

0 comments on commit 57fe11c

Please sign in to comment.