mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
unicode: Renamed no_trans() to the more descriptive deactivate_all(). Added a
verbose_name_raw attribute to the model Options class so that we can more conveniently access the untranslated model name when we need to. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5255 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
267dcdb1e6
commit
abf514053b
@ -4,7 +4,6 @@ Creates content types for all installed models.
|
||||
|
||||
from django.dispatch import dispatcher
|
||||
from django.db.models import get_apps, get_models, signals
|
||||
from django.utils.translation import activate, no_trans, get_language
|
||||
from django.utils.encoding import smart_unicode
|
||||
|
||||
def create_contenttypes(app, created_models, verbosity=2):
|
||||
@ -19,12 +18,9 @@ def create_contenttypes(app, created_models, verbosity=2):
|
||||
ContentType.objects.get(app_label=opts.app_label,
|
||||
model=opts.object_name.lower())
|
||||
except ContentType.DoesNotExist:
|
||||
lang = get_language()
|
||||
no_trans()
|
||||
ct = ContentType(name=smart_unicode(opts.verbose_name),
|
||||
ct = ContentType(name=smart_unicode(opts.verbose_name_raw),
|
||||
app_label=opts.app_label, model=opts.object_name.lower())
|
||||
ct.save()
|
||||
activate(lang)
|
||||
if verbosity >= 2:
|
||||
print "Adding content type '%s | %s'" % (ct.app_label, ct.model)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _, no_trans, activate, get_language
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.encoding import smart_unicode
|
||||
|
||||
CONTENT_TYPE_CACHE = {}
|
||||
@ -16,12 +16,9 @@ class ContentTypeManager(models.Manager):
|
||||
except KeyError:
|
||||
# The unicode() is needed around opts.verbose_name because it might
|
||||
# be a django.utils.functional.__proxy__ object.
|
||||
lang = get_language()
|
||||
no_trans()
|
||||
ct, created = self.model._default_manager.get_or_create(app_label=key[0],
|
||||
model=key[1], defaults={'name': smart_unicode(opts.verbose_name)})
|
||||
model=key[1], defaults={'name': smart_unicode(opts.verbose_name_raw)})
|
||||
CONTENT_TYPE_CACHE[key] = ct
|
||||
activate(lang)
|
||||
return ct
|
||||
|
||||
def clear_cache(self):
|
||||
|
@ -5,6 +5,7 @@ from django.db.models.fields import AutoField, FieldDoesNotExist
|
||||
from django.db.models.loading import get_models
|
||||
from django.db.models.query import orderlist2sql
|
||||
from django.db.models import Manager
|
||||
from django.utils.translation import activate, deactivate_all, get_language
|
||||
from bisect import bisect
|
||||
import re
|
||||
|
||||
@ -41,6 +42,15 @@ class Options(object):
|
||||
self.object_name = cls.__name__
|
||||
self.module_name = self.object_name.lower()
|
||||
self.verbose_name = get_verbose_name(self.object_name)
|
||||
|
||||
# There are a few places where the untranslated verbose name is needed
|
||||
# (so that we get the same value regardless of currently active
|
||||
# locale).
|
||||
lang = get_language()
|
||||
deactivate_all()
|
||||
self.verbose_name_raw = unicode(self.verbose_name)
|
||||
activate(lang)
|
||||
|
||||
# Next, apply any overridden values from 'class Meta'.
|
||||
if self.meta:
|
||||
meta_attrs = self.meta.__dict__
|
||||
|
@ -8,7 +8,7 @@ __all__ = ['gettext', 'gettext_noop', 'gettext_lazy', 'ngettext',
|
||||
'get_language', 'get_language_bidi', 'get_date_formats',
|
||||
'get_partial_date_formats', 'check_for_language', 'to_locale',
|
||||
'get_language_from_request', 'install', 'templatize', 'ugettext',
|
||||
'ungettext', 'no_trans']
|
||||
'ungettext', 'deactivate_all']
|
||||
|
||||
# Here be dragons, so a short explanation of the logic won't hurt:
|
||||
# We are trying to solve two problems: (1) access settings, in particular
|
||||
@ -105,6 +105,6 @@ def install():
|
||||
def templatize(src):
|
||||
return real_templatize(src)
|
||||
|
||||
def no_trans():
|
||||
return real_no_trans()
|
||||
def deactivate_all():
|
||||
return real_deactivate_all()
|
||||
|
||||
|
@ -15,7 +15,7 @@ def ungettext(singular, plural, number):
|
||||
|
||||
string_concat = lambda *strings: ''.join([str(el) for el in strings])
|
||||
activate = lambda x: None
|
||||
deactivate = no_trans = install = lambda: None
|
||||
deactivate = deactivate_all = install = lambda: None
|
||||
get_language = lambda: settings.LANGUAGE_CODE
|
||||
get_language_bidi = lambda: settings.LANGUAGE_CODE in settings.LANGUAGES_BIDI
|
||||
get_date_formats = lambda: (settings.DATE_FORMAT, settings.DATETIME_FORMAT, settings.TIME_FORMAT)
|
||||
|
@ -203,7 +203,7 @@ def deactivate():
|
||||
if currentThread() in _active:
|
||||
del _active[currentThread()]
|
||||
|
||||
def no_trans():
|
||||
def deactivate_all():
|
||||
"""
|
||||
Makes the active translation object a NullTranslations() instance. This is
|
||||
useful when we want delayed translations to appear as the original string
|
||||
|
Loading…
x
Reference in New Issue
Block a user