Make course ids and usage ids opaque to LMS and Studio [partial commit]
This commit updates common/djangoapps. These keys are now objects with a limited interface, and the particular internal representation is managed by the data storage layer (the modulestore). For the LMS, there should be no outward-facing changes to the system. The keys are, for now, a change to internal representation only. For Studio, the new serialized form of the keys is used in urls, to allow for further migration in the future. Co-Author: Andy Armstrong <andya@edx.org> Co-Author: Christina Roberts <christina@edx.org> Co-Author: David Baumgold <db@edx.org> Co-Author: Diana Huang <dkh@edx.org> Co-Author: Don Mitchell <dmitchell@edx.org> Co-Author: Julia Hansbrough <julia@edx.org> Co-Author: Nimisha Asthagiri <nasthagiri@edx.org> Co-Author: Sarina Canelake <sarina@edx.org> [LMS-2370]
This commit is contained in:
@@ -10,6 +10,8 @@ from embargo.fixtures.country_codes import COUNTRY_CODES
|
||||
import socket
|
||||
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from opaque_keys import InvalidKeyError
|
||||
from xmodule.modulestore.locations import SlashSeparatedCourseKey
|
||||
|
||||
|
||||
class EmbargoedCourseForm(forms.ModelForm): # pylint: disable=incomplete-protocol
|
||||
@@ -20,19 +22,29 @@ class EmbargoedCourseForm(forms.ModelForm): # pylint: disable=incomplete-protoc
|
||||
|
||||
def clean_course_id(self):
|
||||
"""Validate the course id"""
|
||||
course_id = self.cleaned_data["course_id"]
|
||||
|
||||
cleaned_id = self.cleaned_data["course_id"]
|
||||
|
||||
try:
|
||||
course_id = SlashSeparatedCourseKey.from_deprecated_string(cleaned_id)
|
||||
|
||||
except InvalidKeyError:
|
||||
msg = 'COURSE NOT FOUND'
|
||||
msg += u' --- Entered course id was: "{0}". '.format(cleaned_id)
|
||||
msg += 'Please recheck that you have supplied a valid course id.'
|
||||
raise forms.ValidationError(msg)
|
||||
|
||||
# Try to get the course. If this returns None, it's not a real course
|
||||
try:
|
||||
course = modulestore().get_course(course_id)
|
||||
except ValueError:
|
||||
msg = 'COURSE NOT FOUND'
|
||||
msg += u' --- Entered course id was: "{0}". '.format(course_id)
|
||||
msg += u' --- Entered course id was: "{0}". '.format(course_id.to_deprecated_string())
|
||||
msg += 'Please recheck that you have supplied a valid course id.'
|
||||
raise forms.ValidationError(msg)
|
||||
if not course:
|
||||
msg = 'COURSE NOT FOUND'
|
||||
msg += u' --- Entered course id was: "{0}". '.format(course_id)
|
||||
msg += u' --- Entered course id was: "{0}". '.format(course_id.to_deprecated_string())
|
||||
msg += 'Please recheck that you have supplied a valid course id.'
|
||||
raise forms.ValidationError(msg)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user