Merge pull request #15776 from edx/christina/slash-the-slash-2

Remove usages of deprecated SlashSeparatedCourseKey.
This commit is contained in:
Christina Roberts
2017-08-14 11:58:31 -04:00
committed by GitHub
59 changed files with 175 additions and 317 deletions

View File

@@ -16,12 +16,9 @@ from django.utils.translation import ugettext
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.decorators.http import require_http_methods, require_POST
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from courseware.courses import get_course_with_access
from edxmako.shortcuts import render_to_response
from lms.djangoapps.django_comment_client.constants import TYPE_ENTRY
from lms.djangoapps.django_comment_client.utils import get_discussion_categories_ids, get_discussion_category_map
from util.json_request import JsonResponse, expect_json
from . import cohorts
@@ -145,7 +142,7 @@ def cohort_handler(request, course_key_string, cohort_id=None):
If no cohort ID is specified, creates a new cohort and returns the JSON representation of the updated
cohort.
"""
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key_string)
course_key = CourseKey.from_string(course_key_string)
course = get_course_with_access(request.user, 'staff', course_key)
if request.method == 'GET':
if not cohort_id:
@@ -221,7 +218,7 @@ def users_in_cohort(request, course_key_string, cohort_id):
}
"""
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key_string)
course_key = CourseKey.from_string(course_key_string)
get_course_with_access(request.user, 'staff', course_key)
@@ -278,7 +275,7 @@ def add_users_to_cohort(request, course_key_string, cohort_id):
Raises Http404 if the cohort cannot be found for the given course.
"""
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key_string)
course_key = CourseKey.from_string(course_key_string)
get_course_with_access(request.user, 'staff', course_key)
try:
@@ -344,7 +341,7 @@ def remove_user_from_cohort(request, course_key_string, cohort_id):
'msg': error_msg}
"""
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key_string)
course_key = CourseKey.from_string(course_key_string)
get_course_with_access(request.user, 'staff', course_key)
username = request.POST.get('username')
@@ -374,7 +371,7 @@ def debug_cohort_mgmt(request, course_key_string):
Debugging view for dev.
"""
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key_string)
course_key = CourseKey.from_string(course_key_string)
# add staff check to make sure it's safe if it's accidentally deployed.
get_course_with_access(request.user, 'staff', course_key)

View File

@@ -25,7 +25,7 @@ from django.utils.http import is_safe_url, urlquote
from django.utils.translation import ugettext as _
from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie
from django_openid_auth import auth as openid_auth
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from opaque_keys.edx.keys import CourseKey
from openid.consumer.consumer import SUCCESS
from openid.extensions import ax, sreg
from openid.server.server import ProtocolError, Server, UntrustedReturnURL
@@ -553,7 +553,7 @@ def course_specific_login(request, course_id):
Dispatcher function for selecting the specific login method
required by the course
"""
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
course_key = CourseKey.from_string(course_id)
course = modulestore().get_course(course_key)
if not course:
# couldn't find the course, will just return vanilla signin page
@@ -576,7 +576,7 @@ def course_specific_register(request, course_id):
Dispatcher function for selecting the specific registration method
required by the course
"""
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
course_key = CourseKey.from_string(course_id)
course = modulestore().get_course(course_key)
if not course:

View File

@@ -10,7 +10,7 @@ from django.views.decorators.debug import sensitive_post_parameters
from django_filters.rest_framework import DjangoFilterBackend
from opaque_keys import InvalidKeyError
from opaque_keys.edx import locator
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from opaque_keys.edx.keys import CourseKey
from rest_framework import authentication, generics, status, viewsets
from rest_framework.exceptions import ParseError
from rest_framework.views import APIView
@@ -216,7 +216,7 @@ class ForumRoleUsersListView(generics.ListAPIView):
course_id_string = self.request.query_params.get('course_id')
if not course_id_string:
raise ParseError('course_id must be specified')
course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id_string)
course_id = CourseKey.from_string(course_id_string)
role = Role.objects.get_or_create(course_id=course_id, name=name)[0]
users = role.users.prefetch_related("preferences").select_related("profile").all()
return users