mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
unicode: Fixed #4292 -- Added support for __unicode__ to lazy() objects.
Thanks, Ivan Sagalaev. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5239 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4c34343e17
commit
03b86ea12d
@ -32,6 +32,8 @@ def lazy(func, *resultclasses):
|
|||||||
self.__dispatch[resultclass] = {}
|
self.__dispatch[resultclass] = {}
|
||||||
for (k, v) in resultclass.__dict__.items():
|
for (k, v) in resultclass.__dict__.items():
|
||||||
setattr(self, k, self.__promise__(resultclass, k, v))
|
setattr(self, k, self.__promise__(resultclass, k, v))
|
||||||
|
if unicode in resultclasses:
|
||||||
|
setattr(self, '__unicode__', self.__unicode_cast)
|
||||||
|
|
||||||
def __promise__(self, klass, funcname, func):
|
def __promise__(self, klass, funcname, func):
|
||||||
# Builds a wrapper around some magic method and registers that magic
|
# Builds a wrapper around some magic method and registers that magic
|
||||||
@ -47,6 +49,9 @@ def lazy(func, *resultclasses):
|
|||||||
self.__dispatch[klass][funcname] = func
|
self.__dispatch[klass][funcname] = func
|
||||||
return __wrapper__
|
return __wrapper__
|
||||||
|
|
||||||
|
def __unicode_cast(self):
|
||||||
|
return self.__func(*self.__args, **self.__kw)
|
||||||
|
|
||||||
def __wrapper__(*args, **kw):
|
def __wrapper__(*args, **kw):
|
||||||
# Creates the proxy object, instead of the actual value.
|
# Creates the proxy object, instead of the actual value.
|
||||||
return __proxy__(args, kw)
|
return __proxy__(args, kw)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user