Ticket #8033: better_error_handling_for_ugettext_r8377.diff
File better_error_handling_for_ugettext_r8377.diff, 3.9 KB (added by , 16 years ago) |
---|
-
django/db/models/loading.py
9 9 import threading 10 10 11 11 __all__ = ('get_apps', 'get_app', 'get_models', 'get_model', 'register_models', 12 'load_app', 'app_cache_ready' )12 'load_app', 'app_cache_ready', 'app_cache_loading') 13 13 14 14 class AppCache(object): 15 15 """ … … 30 30 31 31 # -- Everything below here is only used when populating the cache -- 32 32 loaded = False, 33 loading = False, 33 34 handled = {}, 34 35 postponed = [], 35 36 nesting_level = 0, … … 51 52 try: 52 53 if self.loaded: 53 54 return 55 self.loading = True 54 56 for app_name in settings.INSTALLED_APPS: 55 57 if app_name in self.handled: 56 58 continue … … 59 61 for app_name in self.postponed: 60 62 self.load_app(app_name) 61 63 self.loaded = True 64 self.loading = False 62 65 finally: 63 66 self.write_lock.release() 64 67 … … 92 95 """ 93 96 return self.loaded 94 97 98 def app_cache_loading(self): 99 """ 100 Returns true if the model cache is now loading. 101 """ 102 return self.loading 103 104 95 105 def get_apps(self): 96 106 "Returns a list of all installed modules that contain models." 97 107 self._populate() … … 187 197 register_models = cache.register_models 188 198 load_app = cache.load_app 189 199 app_cache_ready = cache.app_cache_ready 200 app_cache_loading = cache.app_cache_loading -
django/core/exceptions.py
28 28 "Django is somehow improperly configured" 29 29 pass 30 30 31 class ImproperlyImplemented(Exception): 32 "Django is somehow improperly implemented" 33 pass 34 31 35 class FieldError(Exception): 32 36 """Some kind of problem with a model field.""" 33 37 pass -
django/views/debug.py
60 60 61 61 def get_traceback_html(self): 62 62 "Return HTML code for traceback." 63 from django.utils import translation 64 translation.deactivate_all() # avoid possible translation errors in 500 error handling 63 65 64 66 if issubclass(self.exc_type, TemplateDoesNotExist): 65 67 from django.template.loader import template_source_loaders -
django/utils/translation/trans_real.py
7 7 import gettext as gettext_module 8 8 from cStringIO import StringIO 9 9 10 from django.core.exceptions import ImproperlyImplemented 11 from django.db.models.loading import app_cache_loading, get_apps 10 12 from django.utils.safestring import mark_safe, SafeData 11 13 from django.utils.thread_support import currentThread 12 14 … … 270 272 """ 271 273 global _default, _active 272 274 t = _active.get(currentThread(), None) 275 if app_cache_loading() and \ 276 not isinstance(t, gettext_module.NullTranslations): 277 raise ImproperlyImplemented( 278 "django.utils.translation.%(func_name)s function called for " 279 "translation of '%(message)s' when Django apps is still loading." 280 "%(func_name)s function must be called after " 281 "applications loading." % {'func_name': translation_function, 282 'message': message}) 273 283 if t is not None: 274 284 result = getattr(t, translation_function)(message) 275 285 else: