diff --git a/cms/djangoapps/contentstore/admin.py b/cms/djangoapps/contentstore/admin.py index 2a73566ee3..a04928882c 100644 --- a/cms/djangoapps/contentstore/admin.py +++ b/cms/djangoapps/contentstore/admin.py @@ -2,11 +2,12 @@ Admin site bindings for contentstore """ +from __future__ import absolute_import + from config_models.admin import ConfigurationModelAdmin from django.contrib import admin from contentstore.models import PushNotificationConfig, VideoUploadConfig - admin.site.register(VideoUploadConfig, ConfigurationModelAdmin) admin.site.register(PushNotificationConfig, ConfigurationModelAdmin) diff --git a/cms/djangoapps/contentstore/apps.py b/cms/djangoapps/contentstore/apps.py index 770ce3a9a0..65388470ec 100644 --- a/cms/djangoapps/contentstore/apps.py +++ b/cms/djangoapps/contentstore/apps.py @@ -4,6 +4,8 @@ Contentstore Application Configuration Above-modulestore level signal handlers are connected here. """ +from __future__ import absolute_import + from django.apps import AppConfig diff --git a/cms/djangoapps/contentstore/course_group_config.py b/cms/djangoapps/contentstore/course_group_config.py index f07c51eebd..ae02c29220 100644 --- a/cms/djangoapps/contentstore/course_group_config.py +++ b/cms/djangoapps/contentstore/course_group_config.py @@ -1,9 +1,11 @@ """ Class for manipulating groups configuration on a course object. """ -from collections import defaultdict +from __future__ import absolute_import + import json import logging +from collections import defaultdict from django.utils.translation import ugettext as _ diff --git a/cms/djangoapps/contentstore/course_info_model.py b/cms/djangoapps/contentstore/course_info_model.py index d5631d9e94..099de0255d 100644 --- a/cms/djangoapps/contentstore/course_info_model.py +++ b/cms/djangoapps/contentstore/course_info_model.py @@ -12,6 +12,8 @@ Current db representation: } """ +from __future__ import absolute_import + import logging import re diff --git a/cms/djangoapps/contentstore/debug_file_uploader.py b/cms/djangoapps/contentstore/debug_file_uploader.py index 12acfe95c3..30c0651f6d 100644 --- a/cms/djangoapps/contentstore/debug_file_uploader.py +++ b/cms/djangoapps/contentstore/debug_file_uploader.py @@ -1,3 +1,7 @@ +""" Upload file handler to help test progress bars in uploads. """ + +from __future__ import absolute_import + import time from django.core.files.uploadhandler import FileUploadHandler diff --git a/cms/djangoapps/contentstore/models.py b/cms/djangoapps/contentstore/models.py index fa69d45ec7..0100b6e12d 100644 --- a/cms/djangoapps/contentstore/models.py +++ b/cms/djangoapps/contentstore/models.py @@ -2,6 +2,8 @@ Models for contentstore """ +from __future__ import absolute_import + from config_models.models import ConfigurationModel from django.db.models.fields import TextField diff --git a/cms/djangoapps/contentstore/proctoring.py b/cms/djangoapps/contentstore/proctoring.py index 3a86a234ed..474180d21b 100644 --- a/cms/djangoapps/contentstore/proctoring.py +++ b/cms/djangoapps/contentstore/proctoring.py @@ -2,8 +2,11 @@ Code related to the handling of Proctored Exams in Studio """ +from __future__ import absolute_import + import logging +import six from django.conf import settings from edx_proctoring.api import ( create_exam, @@ -36,7 +39,7 @@ def register_special_exams(course_key): course = modulestore().get_course(course_key) if course is None: - raise ItemNotFoundError(u"Course {} does not exist", unicode(course_key)) + raise ItemNotFoundError(u"Course {} does not exist", six.text_type(course_key)) if not course.enable_proctored_exams and not course.enable_timed_exams: # likewise if course does not have these features turned on @@ -66,7 +69,7 @@ def register_special_exams(course_key): for timed_exam in timed_exams: msg = ( u'Found {location} as a timed-exam in course structure. Inspecting...'.format( - location=unicode(timed_exam.location) + location=six.text_type(timed_exam.location) ) ) log.info(msg) @@ -84,7 +87,7 @@ def register_special_exams(course_key): } try: - exam = get_exam_by_content_id(unicode(course_key), unicode(timed_exam.location)) + exam = get_exam_by_content_id(six.text_type(course_key), six.text_type(timed_exam.location)) # update case, make sure everything is synced exam_metadata['exam_id'] = exam['id'] @@ -93,8 +96,8 @@ def register_special_exams(course_key): log.info(msg) except ProctoredExamNotFoundException: - exam_metadata['course_id'] = unicode(course_key) - exam_metadata['content_id'] = unicode(timed_exam.location) + exam_metadata['course_id'] = six.text_type(course_key) + exam_metadata['content_id'] = six.text_type(timed_exam.location) exam_id = create_exam(**exam_metadata) msg = u'Created new timed exam {exam_id}'.format(exam_id=exam_id) @@ -132,7 +135,7 @@ def register_special_exams(course_key): search = [ timed_exam for timed_exam in timed_exams if - unicode(timed_exam.location) == exam['content_id'] + six.text_type(timed_exam.location) == exam['content_id'] ] if not search: # This means it was turned off in Studio, we need to mark diff --git a/cms/djangoapps/contentstore/push_notification.py b/cms/djangoapps/contentstore/push_notification.py index e7ee741c44..b626e3aed5 100644 --- a/cms/djangoapps/contentstore/push_notification.py +++ b/cms/djangoapps/contentstore/push_notification.py @@ -2,17 +2,20 @@ Helper methods for push notifications from Studio. """ +from __future__ import absolute_import + from logging import exception as log_exception from uuid import uuid4 +import six from django.conf import settings +from parse_rest.connection import register +from parse_rest.core import ParseError +from parse_rest.installation import Push from six import text_type from contentstore.models import PushNotificationConfig from contentstore.tasks import push_course_update_task -from parse_rest.connection import register -from parse_rest.core import ParseError -from parse_rest.installation import Push from xmodule.modulestore.django import modulestore @@ -33,7 +36,7 @@ def enqueue_push_course_update(update, course_key): course = modulestore().get_course(course_key) if course: push_course_update_task.delay( - unicode(course_key), + six.text_type(course_key), course.clean_id(padding_char='_'), course.display_name ) @@ -51,7 +54,7 @@ def send_push_course_update(course_key_string, course_subscription_id, course_di ) push_payload = { "action": "course.announcement", - "notification-id": unicode(uuid4()), + "notification-id": six.text_type(uuid4()), "course-id": course_key_string, "course-name": course_display_name, diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 237dd34afc..c6f6ce48ab 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -1,11 +1,12 @@ """ Common utility functions useful throughout the contentstore """ -from __future__ import print_function +from __future__ import absolute_import, print_function import logging from datetime import datetime +import six from django.conf import settings from django.urls import reverse from django.utils.translation import ugettext as _ @@ -150,7 +151,7 @@ def get_lms_link_for_certificate_web_view(user_id, course_key, mode): return u"//{certificate_web_base}/certificates/user/{user_id}/course/{course_id}?preview={mode}".format( certificate_web_base=lms_base, user_id=user_id, - course_id=unicode(course_key), + course_id=six.text_type(course_key), mode=mode ) @@ -274,7 +275,7 @@ def reverse_url(handler_name, key_name=None, key_value=None, kwargs=None): Creates the URL for the given handler. The optional key_name and key_value are passed in as kwargs to the handler. """ - kwargs_for_reverse = {key_name: unicode(key_value)} if key_name else None + kwargs_for_reverse = {key_name: six.text_type(key_value)} if key_name else None if kwargs: kwargs_for_reverse.update(kwargs) return reverse(handler_name, kwargs=kwargs_for_reverse) @@ -427,7 +428,7 @@ def get_user_partition_info(xblock, schemes=None, course=None): # Put together the entire partition dictionary partitions.append({ "id": p.id, - "name": unicode(p.name), # Convert into a string in case ugettext_lazy was used + "name": six.text_type(p.name), # Convert into a string in case ugettext_lazy was used "scheme": p.scheme.name, "groups": groups, })