summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2016-04-02 13:18:26 +0200
committerTim Graham <timograham@gmail.com>2016-04-09 14:54:18 -0400
commitc1aec0feda73ede09503192a66f973598aef901d (patch)
treef1e4c09f3e98177cfe78cc9039b300f8984e7aed /django/utils
parentc16b9dd8e0ae757616e9accbaffecc521191ee98 (diff)
Fixed #25847 -- Made User.is_(anonymous|authenticated) properties.
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/deprecation.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/django/utils/deprecation.py b/django/utils/deprecation.py
index 905bbc4f6d..70216e8c5b 100644
--- a/django/utils/deprecation.py
+++ b/django/utils/deprecation.py
@@ -79,3 +79,33 @@ class DeprecationInstanceCheck(type):
self.deprecation_warning, 2
)
return super(DeprecationInstanceCheck, self).__instancecheck__(instance)
+
+
+class CallableBool:
+ """
+ An boolean-like object that is also callable for backwards compatibility.
+ """
+ do_not_call_in_templates = True
+
+ def __init__(self, value):
+ self.value = value
+
+ def __bool__(self):
+ return self.value
+
+ def __call__(self):
+ warnings.warn(
+ "Using user.is_authenticated() and user.is_anonymous() as a method "
+ "is deprecated. Remove the parentheses to use it as an attribute.",
+ RemovedInDjango20Warning, stacklevel=2
+ )
+ return self.value
+
+ def __nonzero__(self): # Python 2 compatibility
+ return self.value
+
+ def __repr__(self):
+ return 'CallableBool(%r)' % self.value
+
+CallableFalse = CallableBool(False)
+CallableTrue = CallableBool(True)