diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2012-09-07 12:51:11 -0400 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2012-09-07 12:51:11 -0400 |
| commit | d683263f97aedd67f17f4b78ac65d915f4e70d36 (patch) | |
| tree | ef7c4176814ffd35f12fd355444c099e3b3a54b5 /django/db/models | |
| parent | 7e81213b5a4570926afbd67eff7f2675f636d720 (diff) | |
Added SQLite backend which passes all current tests
Diffstat (limited to 'django/db/models')
| -rw-r--r-- | django/db/models/loading.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/django/db/models/loading.py b/django/db/models/loading.py index 0ed6caffa4..e0d943853b 100644 --- a/django/db/models/loading.py +++ b/django/db/models/loading.py @@ -265,6 +265,10 @@ class AppCache(object): self.app_models = state['app_models'] self.app_errors = state['app_errors'] + def temporary_state(self): + "Returns a context manager that restores the state on exit" + return StateContextManager(self) + def unregister_all(self): """ Wipes the AppCache clean of all registered models. @@ -275,6 +279,23 @@ class AppCache(object): self.app_models = SortedDict() self.app_errors = {} + +class StateContextManager(object): + """ + Context manager for locking cache state. + Useful for making temporary models you don't want to stay in the cache. + """ + + def __init__(self, cache): + self.cache = cache + + def __enter__(self): + self.state = self.cache.save_state() + + def __exit__(self, type, value, traceback): + self.cache.restore_state(self.state) + + cache = AppCache() # These methods were always module level, so are kept that way for backwards |
