Merge pull request #20914 from amitvadhel/INCR-467

INCR-467: Updates on Python 3.x
This commit is contained in:
Feanil Patel
2019-07-02 09:59:37 -04:00
committed by GitHub
4 changed files with 27 additions and 17 deletions

View File

@@ -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)

View File

@@ -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()

View File

@@ -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

View File

@@ -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(