diff --git a/AUTHORS b/AUTHORS
index cf03e891ec7..26b2e0540fa 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -407,7 +407,6 @@ answer newbie questions, and generally made Django that much better:
charly.wilhelm@gmail.com
Rachel Willmer
Gary Wilson
- Jakub Wilk
Jakub Wiśniowski
Maciej Wiśniowski
wojtek
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index edd7ba257f8..dd5117fb782 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -191,8 +191,7 @@ class Field(object):
def set_attributes_from_name(self, name):
self.name = name
self.attname, self.column = self.get_attname_column()
- if self.verbose_name is None and name:
- self.verbose_name = name.replace('_', ' ')
+ self.verbose_name = self.verbose_name or (name and name.replace('_', ' '))
def contribute_to_class(self, cls, name):
self.set_attributes_from_name(name)
diff --git a/django/utils/functional.py b/django/utils/functional.py
index e465ab5fec1..3de693e18ce 100644
--- a/django/utils/functional.py
+++ b/django/utils/functional.py
@@ -148,51 +148,42 @@ def lazy(func, *resultclasses):
function is evaluated on every access.
"""
class __proxy__(Promise):
- """
- Encapsulate a function call and act as a proxy for methods that are
- called on the result of that function. The function is not evaluated
- until one of the methods on the result is called.
- """
- __dispatch = None
-
+ # This inner class encapsulates the code that should be evaluated
+ # lazily. On calling of one of the magic methods it will force
+ # the evaluation and store the result. Afterwards, the result
+ # is delivered directly. So the result is memoized.
def __init__(self, args, kw):
self.__func = func
self.__args = args
self.__kw = kw
- if self.__dispatch is None:
- self.__prepare_class__()
-
- def __prepare_class__(cls):
- cls.__dispatch = {}
+ self.__dispatch = {}
for resultclass in resultclasses:
- cls.__dispatch[resultclass] = {}
+ self.__dispatch[resultclass] = {}
for (k, v) in resultclass.__dict__.items():
- if hasattr(cls, k):
- continue
- setattr(cls, k, cls.__promise__(resultclass, k, v))
- cls._delegate_str = str in resultclasses
- cls._delegate_unicode = unicode in resultclasses
- assert not (cls._delegate_str and cls._delegate_unicode), "Cannot call lazy() with both str and unicode return types."
- if cls._delegate_unicode:
- cls.__unicode__ = cls.__unicode_cast
- elif cls._delegate_str:
- cls.__str__ = cls.__str_cast
- __prepare_class__ = classmethod(__prepare_class__)
+ setattr(self, k, self.__promise__(resultclass, k, v))
+ self._delegate_str = str in resultclasses
+ self._delegate_unicode = unicode in resultclasses
+ assert not (self._delegate_str and self._delegate_unicode), "Cannot call lazy() with both str and unicode return types."
+ if self._delegate_unicode:
+ # Each call to lazy() makes a new __proxy__ object, so this
+ # doesn't interfere with any other lazy() results.
+ __proxy__.__unicode__ = __proxy__.__unicode_cast
+ elif self._delegate_str:
+ __proxy__.__str__ = __proxy__.__str_cast
- def __promise__(cls, klass, funcname, func):
+ def __promise__(self, klass, funcname, func):
# Builds a wrapper around some magic method and registers that magic
# method for the given type and method name.
- def __wrapper__(self, *args, **kw):
+ def __wrapper__(*args, **kw):
# Automatically triggers the evaluation of a lazy value and
# applies the given magic method of the result type.
res = self.__func(*self.__args, **self.__kw)
return self.__dispatch[type(res)][funcname](res, *args, **kw)
- if klass not in cls.__dispatch:
- cls.__dispatch[klass] = {}
- cls.__dispatch[klass][funcname] = func
+ if klass not in self.__dispatch:
+ self.__dispatch[klass] = {}
+ self.__dispatch[klass][funcname] = func
return __wrapper__
- __promise__ = classmethod(__promise__)
def __unicode_cast(self):
return self.__func(*self.__args, **self.__kw)