INCR-434 python3 compatibility
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#pylint: disable=missing-docstring
|
||||
from __future__ import absolute_import
|
||||
|
||||
import warnings
|
||||
|
||||
if __name__ == 'courseware':
|
||||
|
||||
@@ -10,33 +10,34 @@ Note: The access control logic in this file does NOT check for enrollment in
|
||||
If enrollment is to be checked, use get_course_with_access in courseware.courses.
|
||||
It is a wrapper around has_access that additionally checks for enrollment.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
import six
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from pytz import UTC
|
||||
from opaque_keys.edx.keys import CourseKey, UsageKey
|
||||
from pytz import UTC
|
||||
from six import text_type
|
||||
from xblock.core import XBlock
|
||||
|
||||
from courseware.access_response import (
|
||||
IncorrectPartitionGroupError,
|
||||
MilestoneAccessError,
|
||||
MobileAvailabilityError,
|
||||
VisibilityError,
|
||||
NoAllowedPartitionGroupsError,
|
||||
VisibilityError
|
||||
)
|
||||
from courseware.access_utils import (
|
||||
ACCESS_DENIED,
|
||||
ACCESS_GRANTED,
|
||||
adjust_start_date,
|
||||
check_course_open_for_learner,
|
||||
check_start_date,
|
||||
debug,
|
||||
in_preview_mode,
|
||||
check_course_open_for_learner,
|
||||
)
|
||||
from courseware.access_response import (
|
||||
NoAllowedPartitionGroupsError,
|
||||
IncorrectPartitionGroupError,
|
||||
in_preview_mode
|
||||
)
|
||||
from courseware.masquerade import get_masquerade_role, is_masquerading_as_student
|
||||
from lms.djangoapps.ccx.custom_exception import CCXLocatorValidationException
|
||||
@@ -162,7 +163,7 @@ def has_access(user, action, obj, course_key=None):
|
||||
if isinstance(obj, UsageKey):
|
||||
return _has_access_location(user, action, obj, course_key)
|
||||
|
||||
if isinstance(obj, basestring):
|
||||
if isinstance(obj, six.string_types):
|
||||
return _has_access_string(user, action, obj)
|
||||
|
||||
# Passing an unknown object here is a coding error, so rather than
|
||||
@@ -812,7 +813,12 @@ def _can_access_descriptor_with_milestones(user, descriptor, course_key):
|
||||
descriptor: the object being accessed
|
||||
course_key: key for the course for this descriptor
|
||||
"""
|
||||
if milestones_helpers.get_course_content_milestones(course_key, unicode(descriptor.location), 'requires', user.id):
|
||||
if milestones_helpers.get_course_content_milestones(
|
||||
course_key,
|
||||
six.text_type(descriptor.location),
|
||||
'requires',
|
||||
user.id
|
||||
):
|
||||
debug("Deny: user has not completed all milestones for content")
|
||||
return ACCESS_DENIED
|
||||
else:
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
This file contains all the classes used by has_access for error handling
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from xmodule.course_metadata_utils import DEFAULT_START_DATE
|
||||
|
||||
@@ -3,6 +3,8 @@ Simple utility functions for computing access.
|
||||
It allows us to share code between access.py and block transformers.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from logging import getLogger
|
||||
|
||||
@@ -11,10 +13,7 @@ from django.utils.translation import ugettext as _
|
||||
from pytz import UTC
|
||||
|
||||
from courseware.access_response import AccessResponse, StartDateError
|
||||
from courseware.masquerade import (
|
||||
get_course_masquerade,
|
||||
is_masquerading_as_student
|
||||
)
|
||||
from courseware.masquerade import get_course_masquerade, is_masquerading_as_student
|
||||
from openedx.core.djangoapps.util.user_messages import PageLevelMessages
|
||||
from openedx.core.djangolib.markup import HTML
|
||||
from openedx.features.course_experience import COURSE_PRE_START_ACCESS_FLAG
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
This file contains the exception used in courseware access
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.http import Http404
|
||||
|
||||
|
||||
|
||||
@@ -14,10 +14,13 @@ package and is used to wrap the `authored_data` when constructing an
|
||||
`LmsFieldData`. This means overrides will be in effect for all scopes covered
|
||||
by `authored_data`, e.g. course content and settings stored in Mongo.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import threading
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from contextlib import contextmanager
|
||||
|
||||
import six
|
||||
from django.conf import settings
|
||||
from edx_django_utils.cache import DEFAULT_REQUEST_CACHE
|
||||
from xblock.field_data import FieldData
|
||||
@@ -91,7 +94,7 @@ def overrides_disabled():
|
||||
return bool(_OVERRIDES_DISABLED.disabled)
|
||||
|
||||
|
||||
class FieldOverrideProvider(object):
|
||||
class FieldOverrideProvider(six.with_metaclass(ABCMeta, object)):
|
||||
"""
|
||||
Abstract class which defines the interface that a `FieldOverrideProvider`
|
||||
must provide. In general, providers should derive from this class, but
|
||||
@@ -102,7 +105,6 @@ class FieldOverrideProvider(object):
|
||||
field overrides. To set overrides, there will be a domain specific API for
|
||||
the concrete override implementation being used.
|
||||
"""
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
def __init__(self, user, fallback_field_data):
|
||||
self.user = user
|
||||
@@ -187,7 +189,7 @@ class OverrideFieldData(FieldData):
|
||||
if course is None:
|
||||
cache_key = ENABLED_OVERRIDE_PROVIDERS_KEY.format(course_id='None')
|
||||
else:
|
||||
cache_key = ENABLED_OVERRIDE_PROVIDERS_KEY.format(course_id=unicode(course.id))
|
||||
cache_key = ENABLED_OVERRIDE_PROVIDERS_KEY.format(course_id=six.text_type(course.id))
|
||||
enabled_providers = request_cache.data.get(cache_key, NOTSET)
|
||||
if enabled_providers == NOTSET:
|
||||
enabled_providers = tuple(
|
||||
@@ -234,7 +236,7 @@ class OverrideFieldData(FieldData):
|
||||
# If this is an inheritable field and an override is set above,
|
||||
# then we want to return False here, so the field_data uses the
|
||||
# override and not the original value for this block.
|
||||
inheritable = InheritanceMixin.fields.keys()
|
||||
inheritable = list(InheritanceMixin.fields.keys()) # pylint: disable=no-member
|
||||
if name in inheritable:
|
||||
for ancestor in _lineage(block):
|
||||
if self.get_override(ancestor, name) is not NOTSET:
|
||||
@@ -249,7 +251,7 @@ class OverrideFieldData(FieldData):
|
||||
# The `default` method is overloaded by the field storage system to
|
||||
# also handle inheritance.
|
||||
if self.providers and not overrides_disabled():
|
||||
inheritable = InheritanceMixin.fields.keys()
|
||||
inheritable = list(InheritanceMixin.fields.keys()) # pylint: disable=no-member
|
||||
if name in inheritable:
|
||||
for ancestor in _lineage(block):
|
||||
value = self.get_override(ancestor, name)
|
||||
@@ -294,7 +296,7 @@ class OverrideModulestoreFieldData(OverrideFieldData):
|
||||
Arguments:
|
||||
block: An XBlock
|
||||
"""
|
||||
course_id = unicode(block.location.course_key)
|
||||
course_id = six.text_type(block.location.course_key)
|
||||
cache_key = ENABLED_MODULESTORE_OVERRIDE_PROVIDERS_KEY.format(course_id=course_id)
|
||||
|
||||
request_cache = DEFAULT_REQUEST_CACHE
|
||||
|
||||
@@ -4,9 +4,11 @@ Allow course staff to see a student or staff view of courseware.
|
||||
Which kind of view has been selected is stored in the session state.
|
||||
'''
|
||||
|
||||
import logging
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
This module is essentially a broker to xmodule/tabs.py -- it was originally introduced to
|
||||
perform some LMS-specific tab display gymnastics for the Entrance Exams feature
|
||||
"""
|
||||
from courseware.access import has_access
|
||||
from courseware.entrance_exams import user_can_skip_entrance_exam
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.translation import ugettext_noop
|
||||
|
||||
from courseware.access import has_access
|
||||
from courseware.entrance_exams import user_can_skip_entrance_exam
|
||||
from openedx.core.lib.course_tabs import CourseTabPluginManager
|
||||
from openedx.features.course_experience import UNIFIED_COURSE_TAB_FLAG, default_course_url_name
|
||||
from student.models import CourseEnrollment
|
||||
@@ -291,7 +295,7 @@ class SingleTextbookTab(CourseTab):
|
||||
def __init__(self, name, tab_id, view_name, index):
|
||||
def link_func(course, reverse_func, index=index):
|
||||
""" Constructs a link for textbooks from a view name, a course, and an index. """
|
||||
return reverse_func(view_name, args=[unicode(course.id), index])
|
||||
return reverse_func(view_name, args=[six.text_type(course.id), index])
|
||||
|
||||
tab_dict = dict()
|
||||
tab_dict['name'] = name
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
"""
|
||||
Module to define url helpers functions
|
||||
"""
|
||||
from urllib import urlencode
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six
|
||||
from django.urls import reverse
|
||||
from six.moves.urllib.parse import urlencode # pylint: disable=import-error
|
||||
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.search import navigation_index, path_to_location
|
||||
@@ -32,13 +34,13 @@ def get_redirect_url(course_key, usage_key):
|
||||
# args provided by the redirect.
|
||||
# Rely on index to do all error handling and access control.
|
||||
if chapter is None:
|
||||
redirect_url = reverse('courseware', args=(unicode(course_key), ))
|
||||
redirect_url = reverse('courseware', args=(six.text_type(course_key), ))
|
||||
elif section is None:
|
||||
redirect_url = reverse('courseware_chapter', args=(unicode(course_key), chapter))
|
||||
redirect_url = reverse('courseware_chapter', args=(six.text_type(course_key), chapter))
|
||||
elif position is None:
|
||||
redirect_url = reverse(
|
||||
'courseware_section',
|
||||
args=(unicode(course_key), chapter, section)
|
||||
args=(six.text_type(course_key), chapter, section)
|
||||
)
|
||||
else:
|
||||
# Here we use the navigation_index from the position returned from
|
||||
@@ -46,7 +48,7 @@ def get_redirect_url(course_key, usage_key):
|
||||
# moment
|
||||
redirect_url = reverse(
|
||||
'courseware_position',
|
||||
args=(unicode(course_key), chapter, section, navigation_index(position))
|
||||
args=(six.text_type(course_key), chapter, section, navigation_index(position))
|
||||
)
|
||||
redirect_url += "?{}".format(urlencode({'activate_block_id': unicode(final_target_id)}))
|
||||
redirect_url += "?{}".format(urlencode({'activate_block_id': six.text_type(final_target_id)}))
|
||||
return redirect_url
|
||||
|
||||
Reference in New Issue
Block a user