From c1aec0feda73ede09503192a66f973598aef901d Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Sat, 2 Apr 2016 13:18:26 +0200 Subject: Fixed #25847 -- Made User.is_(anonymous|authenticated) properties. --- django/utils/deprecation.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'django/utils') 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) -- cgit v1.3