INCR-430 python3 compatibility
This commit is contained in:
@@ -2,17 +2,19 @@
|
||||
API function for retrieving course blocks data
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import lms.djangoapps.course_blocks.api as course_blocks_api
|
||||
from lms.djangoapps.course_blocks.transformers.access_denied_filter import AccessDeniedMessageFilterTransformer
|
||||
from lms.djangoapps.course_blocks.transformers.hidden_content import HiddenContentTransformer
|
||||
from lms.djangoapps.course_blocks.transformers.hide_empty import HideEmptyTransformer
|
||||
from lms.djangoapps.course_blocks.transformers.access_denied_filter import AccessDeniedMessageFilterTransformer
|
||||
from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers
|
||||
from openedx.core.djangoapps.waffle_utils import WaffleFlag, WaffleFlagNamespace
|
||||
from openedx.core.lib.mobile_utils import is_request_from_mobile_app
|
||||
|
||||
from .serializers import BlockDictSerializer, BlockSerializer
|
||||
from .transformers.blocks_api import BlocksAPITransformer
|
||||
from .transformers.block_completion import BlockCompletionTransformer
|
||||
from .transformers.blocks_api import BlocksAPITransformer
|
||||
from .transformers.milestones import MilestonesAndSpecialExamsTransformer
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
"""
|
||||
Course API Forms
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.forms import CharField, ChoiceField, Form, IntegerField
|
||||
@@ -73,7 +76,7 @@ class BlockListGetForm(Form):
|
||||
try:
|
||||
usage_key = UsageKey.from_string(usage_key)
|
||||
except InvalidKeyError:
|
||||
raise ValidationError(u"'{}' is not a valid usage key.".format(unicode(usage_key)))
|
||||
raise ValidationError(u"'{}' is not a valid usage key.".format(six.text_type(usage_key)))
|
||||
|
||||
return usage_key.replace(course_key=modulestore().fill_in_run(usage_key.course_key))
|
||||
|
||||
@@ -131,7 +134,7 @@ class BlockListGetForm(Form):
|
||||
if not permissions.can_access_all_blocks(requesting_user, course_key):
|
||||
raise PermissionDenied(
|
||||
u"'{requesting_username}' does not have permission to access all blocks in '{course_key}'."
|
||||
.format(requesting_username=requesting_user.username, course_key=unicode(course_key))
|
||||
.format(requesting_username=requesting_user.username, course_key=six.text_type(course_key))
|
||||
)
|
||||
|
||||
# return None for user
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
Encapsulates permissions checks for Course Blocks API
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from courseware.access import has_access
|
||||
from student.models import CourseEnrollment
|
||||
from student.roles import CourseStaffRole
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
"""
|
||||
Serializers for Course Blocks related return objects.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six
|
||||
from django.conf import settings
|
||||
from rest_framework import serializers
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
from .transformers import SUPPORTED_FIELDS
|
||||
|
||||
|
||||
# This lists the names of all fields that are allowed
|
||||
# to be show to users who do not have access to a particular piece
|
||||
# of content
|
||||
@@ -60,16 +62,16 @@ class BlockSerializer(serializers.Serializer): # pylint: disable=abstract-metho
|
||||
authorization_denial_message = block_structure.get_xblock_field(block_key, 'authorization_denial_message')
|
||||
|
||||
data = {
|
||||
'id': unicode(block_key),
|
||||
'block_id': unicode(block_key.block_id),
|
||||
'id': six.text_type(block_key),
|
||||
'block_id': six.text_type(block_key.block_id),
|
||||
'lms_web_url': reverse(
|
||||
'jump_to',
|
||||
kwargs={'course_id': unicode(block_key.course_key), 'location': unicode(block_key)},
|
||||
kwargs={'course_id': six.text_type(block_key.course_key), 'location': six.text_type(block_key)},
|
||||
request=self.context['request'],
|
||||
),
|
||||
'student_view_url': reverse(
|
||||
'render_xblock',
|
||||
kwargs={'usage_key_string': unicode(block_key)},
|
||||
kwargs={'usage_key_string': six.text_type(block_key)},
|
||||
request=self.context['request'],
|
||||
),
|
||||
}
|
||||
@@ -77,7 +79,7 @@ class BlockSerializer(serializers.Serializer): # pylint: disable=abstract-metho
|
||||
if settings.FEATURES.get("ENABLE_LTI_PROVIDER") and 'lti_url' in self.context['requested_fields']:
|
||||
data['lti_url'] = reverse(
|
||||
'lti_provider_launch',
|
||||
kwargs={'course_id': unicode(block_key.course_key), 'usage_id': unicode(block_key)},
|
||||
kwargs={'course_id': six.text_type(block_key.course_key), 'usage_id': six.text_type(block_key)},
|
||||
request=self.context['request'],
|
||||
)
|
||||
|
||||
@@ -97,7 +99,7 @@ class BlockSerializer(serializers.Serializer): # pylint: disable=abstract-metho
|
||||
if 'children' in self.context['requested_fields']:
|
||||
children = block_structure.get_children(block_key)
|
||||
if children:
|
||||
data['children'] = [unicode(child) for child in children]
|
||||
data['children'] = [six.text_type(child) for child in children]
|
||||
|
||||
if authorization_denial_reason and authorization_denial_message:
|
||||
data['authorization_denial_reason'] = authorization_denial_reason
|
||||
@@ -122,6 +124,6 @@ class BlockDictSerializer(serializers.Serializer): # pylint: disable=abstract-m
|
||||
Serialize to a dictionary of blocks keyed by the block's usage_key.
|
||||
"""
|
||||
return {
|
||||
unicode(block_key): BlockSerializer(block_key, context=self.context).data
|
||||
six.text_type(block_key): BlockSerializer(block_key, context=self.context).data
|
||||
for block_key in structure
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Course Block API URLs
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.conf import settings
|
||||
from django.conf.urls import url
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
"""
|
||||
CourseBlocks API views
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.http import Http404
|
||||
from opaque_keys import InvalidKeyError
|
||||
@@ -280,5 +283,5 @@ class BlocksInCourseView(BlocksView):
|
||||
course_key = CourseKey.from_string(course_key_string)
|
||||
course_usage_key = modulestore().make_course_usage_key(course_key)
|
||||
except InvalidKeyError:
|
||||
raise ValidationError(u"'{}' is not a valid course key.".format(unicode(course_key_string)))
|
||||
raise ValidationError(u"'{}' is not a valid course key.".format(six.text_type(course_key_string)))
|
||||
return super(BlocksInCourseView, self).list(request, course_usage_key, hide_access_denials=hide_access_denials)
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
Course API Serializers. Representing course catalog data
|
||||
"""
|
||||
|
||||
import urllib
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six.moves.urllib.error # pylint: disable=import-error
|
||||
import six.moves.urllib.parse # pylint: disable=import-error
|
||||
import six.moves.urllib.request # pylint: disable=import-error
|
||||
from django.urls import reverse
|
||||
from rest_framework import serializers
|
||||
|
||||
@@ -92,7 +95,7 @@ class CourseSerializer(serializers.Serializer): # pylint: disable=abstract-meth
|
||||
"""
|
||||
base_url = '?'.join([
|
||||
reverse('blocks_in_course'),
|
||||
urllib.urlencode({'course_id': course_overview.id}),
|
||||
six.moves.urllib.parse.urlencode({'course_id': course_overview.id}),
|
||||
])
|
||||
return self.context['request'].build_absolute_uri(base_url)
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Course API URLs
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.conf import settings
|
||||
from django.conf.urls import include, url
|
||||
|
||||
|
||||
Reference in New Issue
Block a user