Eric Fischer
2018-05-02 10:03:50 -04:00
parent a1869d67f2
commit e18448e27d
79 changed files with 137 additions and 137 deletions

View File

@@ -60,7 +60,7 @@ def get_bookmarks(user, course_key=None, fields=None, serialized=True):
Returns:
List of dicts if serialized is True else queryset.
"""
if user.is_authenticated():
if user.is_authenticated:
bookmarks_queryset = Bookmark.objects.filter(user=user)
if course_key:

View File

@@ -9,7 +9,7 @@ avoid querying the database for a ``User`` instance in each request.
Whilst the built-in ``AuthenticationMiddleware`` mechanism will only obtain the
``User`` instance when it is required, the vast majority of sites will do so on
every page to render "Logged in as 'X'" text as well to evaluate the result of
``user.is_authenticated()`` and ``user.is_superuser`` to provide conditional
``user.is_authenticated`` and ``user.is_superuser`` to provide conditional
functionality.
This middleware eliminates the cost of retrieving this ``User`` instance by

View File

@@ -255,7 +255,7 @@ class StaticContentServer(object):
if not self.is_content_locked(content):
return True
if not hasattr(request, "user") or not request.user.is_authenticated():
if not hasattr(request, "user") or not request.user.is_authenticated:
return False
if not request.user.is_staff:

View File

@@ -116,7 +116,7 @@ class DarkLangMiddleware(object):
"""
Check the user's dark language setting in the session and apply it
"""
auth_user = request.user.is_authenticated()
auth_user = request.user.is_authenticated
preview_lang = None
if auth_user:
# Get the request user's dark lang preference

View File

@@ -80,7 +80,7 @@ class PreviewLanguageFragmentView(EdxFragmentView):
"""
if not DarkLangConfig.current().enabled:
return False
return user and not user.is_anonymous()
return user and not user.is_anonymous
def _set_preview_language(self, request):
"""

View File

@@ -401,7 +401,7 @@ def ssl_login_shortcut(func):
return func(*args, **kwargs)
request = args[0]
if request.user and request.user.is_authenticated(): # don't re-authenticate
if request.user and request.user.is_authenticated: # don't re-authenticate
return func(*args, **kwargs)
cert = ssl_get_cert_from_request(request)
@@ -484,7 +484,7 @@ def cas_login(request, next_page=None, required=False):
ret = django_cas_login(request, next_page, required)
if request.user.is_authenticated():
if request.user.is_authenticated:
user = request.user
UserProfile.objects.get_or_create(
user=user,

View File

@@ -29,7 +29,7 @@ class LanguagePreferenceMiddleware(object):
"""
cookie_lang = request.COOKIES.get(settings.LANGUAGE_COOKIE, None)
if cookie_lang:
if request.user.is_authenticated():
if request.user.is_authenticated:
set_user_preference(request.user, LANGUAGE_KEY, cookie_lang)
else:
request._anonymous_user_cookie_lang = cookie_lang
@@ -57,7 +57,7 @@ class LanguagePreferenceMiddleware(object):
if hasattr(request, 'user'):
current_user = getattr(request.user, 'real_user', request.user)
if current_user and current_user.is_authenticated():
if current_user and current_user.is_authenticated:
anonymous_cookie_lang = getattr(request, '_anonymous_user_cookie_lang', None)
if anonymous_cookie_lang:
user_pref = anonymous_cookie_lang

View File

@@ -572,7 +572,7 @@ class ProgramDataExtender(object):
if is_learner_eligible_for_one_click_purchase:
courses = self.data['courses']
if not self.user.is_anonymous():
if not self.user.is_anonymous:
courses = self._filter_out_courses_with_enrollments(courses)
courses = self._filter_out_courses_with_entitlements(courses)
@@ -606,7 +606,7 @@ class ProgramDataExtender(object):
try:
api_user = self.user
is_anonymous = False
if not self.user.is_authenticated():
if not self.user.is_authenticated:
user = get_user_model()
service_user = user.objects.get(username=settings.ECOMMERCE_SERVICE_WORKER_USERNAME)
api_user = service_user
@@ -787,7 +787,7 @@ class ProgramMarketingDataExtender(ProgramDataExtender):
pass
def _attach_course_run_upgrade_url(self, run_mode):
if not self.user.is_anonymous():
if not self.user.is_anonymous:
super(ProgramMarketingDataExtender, self)._attach_course_run_upgrade_url(run_mode)
else:
run_mode['upgrade_url'] = None

View File

@@ -24,7 +24,7 @@ class SessionInactivityTimeout(object):
"""
Standard entry point for processing requests in Django
"""
if not hasattr(request, "user") or not request.user.is_authenticated():
if not hasattr(request, "user") or not request.user.is_authenticated:
#Can't log out if not logged in
return

View File

@@ -30,7 +30,7 @@ def user_can_preview_themes(user):
"""
Returns true if the specified user is allowed to preview themes.
"""
if not user or user.is_anonymous():
if not user or user.is_anonymous:
return False
# In development mode, all users can preview themes
@@ -46,7 +46,7 @@ def get_user_preview_site_theme(request):
Returns the preview site for the current user, or None if not set.
"""
user = request.user
if not user or user.is_anonymous():
if not user or user.is_anonymous:
return None
preview_site_name = get_user_preference(user, PREVIEW_SITE_THEME_PREFERENCE_KEY)
if not preview_site_name:

View File

@@ -482,7 +482,7 @@ def shim_student_view(view_func, check_logged_in=False):
# the request through authentication middleware.
is_authenticated = (
getattr(request, 'user', None) is not None
and request.user.is_authenticated()
and request.user.is_authenticated
)
if check_logged_in and not is_authenticated:
# If we get a 403 status code from the student view

View File

@@ -35,7 +35,7 @@ class UserTagsEventContextMiddleware(object):
if course_id:
context['course_id'] = course_id
if request.user.is_authenticated():
if request.user.is_authenticated:
context['course_user_tags'] = dict(
UserCourseTag.objects.filter(
user=request.user.pk,

View File

@@ -14,7 +14,7 @@ class SystemUserTestCase(unittest.TestCase):
def test_system_user_is_anonymous(self):
self.assertIsInstance(self.sysuser, AnonymousUser)
self.assertTrue(self.sysuser.is_anonymous())
self.assertTrue(self.sysuser.is_anonymous)
self.assertIsNone(self.sysuser.id)
def test_system_user_has_custom_unicode_representation(self):

View File

@@ -58,7 +58,7 @@ class SessionAuthenticationAllowInactiveUser(SessionAuthentication):
# This is where regular `SessionAuthentication` checks that the user is active.
# We have removed that check in this implementation.
# But we added a check to prevent anonymous users since we require a logged-in account.
if not user or user.is_anonymous():
if not user or user.is_anonymous:
return None
self.enforce_csrf(request)

View File

@@ -173,7 +173,7 @@ class DiscussionXBlock(XBlock, StudioEditableXBlockMixin, XmlParserMixin):
login_msg = ''
if not self.django_user.is_authenticated():
if not self.django_user.is_authenticated:
qs = urllib.urlencode({
'course_id': self.course_key,
'enrollment_action': 'enroll',

View File

@@ -48,7 +48,7 @@ class CourseDatesFragmentMobileView(CourseDatesFragmentView):
template_name = 'course_experience/mobile/course-dates-fragment.html'
def get(self, request, *args, **kwargs):
if not request.user.is_authenticated():
if not request.user.is_authenticated:
raise Http404
return super(CourseDatesFragmentMobileView, self).get(request, *args, **kwargs)

View File

@@ -116,7 +116,7 @@ class CourseHomeFragmentView(EdxFragmentView):
# Unenrolled users who are not course or global staff are given only a subset.
enrollment = CourseEnrollment.get_enrollment(request.user, course_key)
user_access = {
'is_anonymous': request.user.is_anonymous(),
'is_anonymous': request.user.is_anonymous,
'is_enrolled': enrollment is not None,
'is_staff': has_access(request.user, 'staff', course_key),
}

View File

@@ -238,7 +238,7 @@ class EnterpriseApiClient(object):
a response. This exception is raised for both connection timeout and read timeout.
"""
if not user.is_authenticated():
if not user.is_authenticated:
return None
api_resource_name = 'enterprise-learner'
@@ -362,7 +362,7 @@ def enterprise_customer_from_cache(request=None, uuid=None):
enterprise_customer = cache.get(cache_key)
# Check if it's cached in the session.
if not enterprise_customer and request and request.user.is_authenticated():
if not enterprise_customer and request and request.user.is_authenticated:
enterprise_customer = request.session.get('enterprise_customer')
return enterprise_customer
@@ -379,7 +379,7 @@ def enterprise_customer_from_api(request):
# from the EnterpriseCustomer API.
enterprise_api_client = (
EnterpriseApiClient(user=request.user)
if request.user.is_authenticated()
if request.user.is_authenticated
else EnterpriseApiServiceClient()
)
@@ -422,7 +422,7 @@ def enterprise_customer_uuid_for_request(request):
settings.ENTERPRISE_CUSTOMER_COOKIE_NAME
)
if not enterprise_customer_uuid and request.user.is_authenticated():
if not enterprise_customer_uuid and request.user.is_authenticated:
# If there's no way to get an Enterprise UUID for the request, check to see
# if there's already an Enterprise attached to the requesting user on the backend.
learner_data = get_enterprise_learner_data(request.user)

View File

@@ -25,5 +25,5 @@ class EnterpriseMiddleware(object):
"""
Fill the request with Enterprise-related content.
"""
if 'enterprise_customer' not in request.session and request.user.is_authenticated():
if 'enterprise_customer' not in request.session and request.user.is_authenticated:
request.session['enterprise_customer'] = api.enterprise_customer_for_request(request)