From 06582d597217df864055279ae31028ad0a7eeae3 Mon Sep 17 00:00:00 2001 From: amitvadhel Date: Thu, 27 Jun 2019 21:46:03 +0300 Subject: [PATCH] INCR-467: Updates on Python 3.x --- lms/djangoapps/ccx/modulestore.py | 5 ++++- lms/djangoapps/ccx/overrides.py | 8 +++++--- lms/djangoapps/ccx/plugins.py | 2 ++ lms/djangoapps/ccx/views.py | 29 ++++++++++++++++------------- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/lms/djangoapps/ccx/modulestore.py b/lms/djangoapps/ccx/modulestore.py index 85b2d4b9ad..3d8878f6b9 100644 --- a/lms/djangoapps/ccx/modulestore.py +++ b/lms/djangoapps/ccx/modulestore.py @@ -9,9 +9,12 @@ CourseLocator or BlockUsageLocator will actually be used. And all objects returned from the modulestore will have their keys updated to be the CCX version that was passed in. """ +from __future__ import absolute_import + from contextlib import contextmanager from functools import partial +import six from ccx_keys.locator import CCXBlockUsageLocator, CCXLocator from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator @@ -68,7 +71,7 @@ def restore_ccx_collection(field_value, ccx_id=None): if isinstance(field_value, list): field_value = [restore_ccx(fv, ccx_id) for fv in field_value] elif isinstance(field_value, dict): - for key, val in field_value.iteritems(): + for key, val in six.iteritems(field_value): field_value[key] = restore_ccx(val, ccx_id) else: field_value = restore_ccx(field_value, ccx_id) diff --git a/lms/djangoapps/ccx/overrides.py b/lms/djangoapps/ccx/overrides.py index e93d53123b..eef5a22c98 100644 --- a/lms/djangoapps/ccx/overrides.py +++ b/lms/djangoapps/ccx/overrides.py @@ -2,6 +2,8 @@ API related to providing field overrides for individual students. This is used by the individual custom courses feature. """ +from __future__ import absolute_import + import json import logging @@ -9,9 +11,9 @@ from ccx_keys.locator import CCXBlockUsageLocator, CCXLocator from django.db import transaction from opaque_keys.edx.keys import CourseKey, UsageKey -from openedx.core.lib.cache_utils import get_cache -from lms.djangoapps.courseware.field_overrides import FieldOverrideProvider from lms.djangoapps.ccx.models import CcxFieldOverride, CustomCourseForEdX +from lms.djangoapps.courseware.field_overrides import FieldOverrideProvider +from openedx.core.lib.cache_utils import get_cache log = logging.getLogger(__name__) @@ -213,7 +215,7 @@ def bulk_delete_ccx_override_fields(ccx, ids): """ Bulk delete for CcxFieldOverride model """ - ids = filter(None, ids) + ids = [ccx_id for ccx_id in ids if ccx_id] ids = list(set(ids)) if ids: CcxFieldOverride.objects.filter(ccx=ccx, id__in=ids).delete() diff --git a/lms/djangoapps/ccx/plugins.py b/lms/djangoapps/ccx/plugins.py index 650c7bb7f2..37a7522b59 100644 --- a/lms/djangoapps/ccx/plugins.py +++ b/lms/djangoapps/ccx/plugins.py @@ -2,6 +2,8 @@ Registers the CCX feature for the edX platform. """ +from __future__ import absolute_import + from django.conf import settings from django.utils.translation import ugettext_noop diff --git a/lms/djangoapps/ccx/views.py b/lms/djangoapps/ccx/views.py index 9cced12070..a47921a7a0 100644 --- a/lms/djangoapps/ccx/views.py +++ b/lms/djangoapps/ccx/views.py @@ -1,6 +1,8 @@ """ Views related to the Custom Courses feature. """ +from __future__ import absolute_import + import csv import datetime import functools @@ -10,14 +12,15 @@ from copy import deepcopy from cStringIO import StringIO import pytz +import six from ccx_keys.locator import CCXLocator from django.conf import settings from django.contrib import messages from django.contrib.auth.models import User -from django.urls import reverse from django.db import transaction from django.http import Http404, HttpResponse, HttpResponseForbidden from django.shortcuts import redirect +from django.urls import reverse from django.utils.translation import ugettext as _ from django.views.decorators.cache import cache_control from django.views.decorators.csrf import ensure_csrf_cookie @@ -43,7 +46,7 @@ from lms.djangoapps.ccx.utils import ( get_ccx_for_coach, get_date, get_enrollment_action_and_identifiers, - parse_date, + parse_date ) from lms.djangoapps.courseware.field_overrides import disable_overrides from lms.djangoapps.grades.api import CourseGradeFactory @@ -123,7 +126,7 @@ def dashboard(request, course, ccx=None): if ccx: url = reverse( 'ccx_coach_dashboard', - kwargs={'course_id': CCXLocator.from_course_locator(course.id, unicode(ccx.id))} + kwargs={'course_id': CCXLocator.from_course_locator(course.id, six.text_type(ccx.id))} ) return redirect(url) @@ -134,7 +137,7 @@ def dashboard(request, course, ccx=None): context.update(get_ccx_creation_dict(course)) if ccx: - ccx_locator = CCXLocator.from_course_locator(course.id, unicode(ccx.id)) + ccx_locator = CCXLocator.from_course_locator(course.id, six.text_type(ccx.id)) # At this point we are done with verification that current user is ccx coach. assign_staff_role_to_ccx(ccx_locator, request.user, course.id) schedule = get_ccx_schedule(course, ccx) @@ -211,7 +214,7 @@ def create_ccx(request, course, ccx=None): for vertical in sequential.get_children(): override_field_for_ccx(ccx, vertical, hidden, True) - ccx_id = CCXLocator.from_course_locator(course.id, unicode(ccx.id)) + ccx_id = CCXLocator.from_course_locator(course.id, six.text_type(ccx.id)) # Create forum roles seed_permissions_roles(ccx_id) @@ -236,7 +239,7 @@ def create_ccx(request, course, ccx=None): # using CCX object as sender here. responses = SignalHandler.course_published.send( sender=ccx, - course_key=CCXLocator.from_course_locator(course.id, unicode(ccx.id)) + course_key=CCXLocator.from_course_locator(course.id, six.text_type(ccx.id)) ) for rec, response in responses: log.info(u'Signal fired when course is published. Receiver: %s. Response: %s', rec, response) @@ -335,7 +338,7 @@ def save_ccx(request, course, ccx=None): # using CCX object as sender here. responses = SignalHandler.course_published.send( sender=ccx, - course_key=CCXLocator.from_course_locator(course.id, unicode(ccx.id)) + course_key=CCXLocator.from_course_locator(course.id, six.text_type(ccx.id)) ) for rec, response in responses: log.info(u'Signal fired when course is published. Receiver: %s. Response: %s', rec, response) @@ -364,14 +367,14 @@ def set_grading_policy(request, course, ccx=None): # using CCX object as sender here. responses = SignalHandler.course_published.send( sender=ccx, - course_key=CCXLocator.from_course_locator(course.id, unicode(ccx.id)) + course_key=CCXLocator.from_course_locator(course.id, six.text_type(ccx.id)) ) for rec, response in responses: log.info(u'Signal fired when course is published. Receiver: %s. Response: %s', rec, response) url = reverse( 'ccx_coach_dashboard', - kwargs={'course_id': CCXLocator.from_course_locator(course.id, unicode(ccx.id))} + kwargs={'course_id': CCXLocator.from_course_locator(course.id, six.text_type(ccx.id))} ) return redirect(url) @@ -470,7 +473,7 @@ def ccx_students_management(request, course, ccx=None): action, identifiers = get_enrollment_action_and_identifiers(request) email_students = 'email-students' in request.POST - course_key = CCXLocator.from_course_locator(course.id, unicode(ccx.id)) + course_key = CCXLocator.from_course_locator(course.id, six.text_type(ccx.id)) email_params = get_email_params(course, auto_enroll=True, course_key=course_key, display_name=ccx.display_name) errors = ccx_students_enrolling_center(action, identifiers, email_students, course_key, email_params, ccx.coach) @@ -493,7 +496,7 @@ def ccx_gradebook(request, course, ccx=None): if not ccx: raise Http404 - ccx_key = CCXLocator.from_course_locator(course.id, unicode(ccx.id)) + ccx_key = CCXLocator.from_course_locator(course.id, six.text_type(ccx.id)) with ccx_course(ccx_key) as course: student_info, page = get_grade_book_page(request, course, course_key=ccx_key) @@ -505,7 +508,7 @@ def ccx_gradebook(request, course, ccx=None): 'course_id': course.id, 'staff_access': request.user.is_staff, 'ordered_grades': sorted( - course.grade_cutoffs.items(), key=lambda i: i[1], reverse=True), + list(course.grade_cutoffs.items()), key=lambda i: i[1], reverse=True), }) @@ -520,7 +523,7 @@ def ccx_grades_csv(request, course, ccx=None): if not ccx: raise Http404 - ccx_key = CCXLocator.from_course_locator(course.id, unicode(ccx.id)) + ccx_key = CCXLocator.from_course_locator(course.id, six.text_type(ccx.id)) with ccx_course(ccx_key) as course: enrolled_students = User.objects.filter(