Commit ff525bea by Ben McMorran

Fix field serialization

parent bb90c307
...@@ -4,7 +4,9 @@ This file contains celery tasks for contentstore views ...@@ -4,7 +4,9 @@ This file contains celery tasks for contentstore views
from celery.task import task from celery.task import task
from django.contrib.auth.models import User from django.contrib.auth.models import User
import json
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.course_module import CourseFields
from xmodule.modulestore.exceptions import DuplicateCourseError, ItemNotFoundError from xmodule.modulestore.exceptions import DuplicateCourseError, ItemNotFoundError
from course_action_state.models import CourseRerunState from course_action_state.models import CourseRerunState
...@@ -18,9 +20,10 @@ def rerun_course(source_course_key_string, destination_course_key_string, user_i ...@@ -18,9 +20,10 @@ def rerun_course(source_course_key_string, destination_course_key_string, user_i
Reruns a course in a new celery task. Reruns a course in a new celery task.
""" """
try: try:
# deserialize the keys # deserialize the payload
source_course_key = CourseKey.from_string(source_course_key_string) source_course_key = CourseKey.from_string(source_course_key_string)
destination_course_key = CourseKey.from_string(destination_course_key_string) destination_course_key = CourseKey.from_string(destination_course_key_string)
fields = deserialize_fields(fields)
# use the split modulestore as the store for the rerun course, # use the split modulestore as the store for the rerun course,
# as the Mongo modulestore doesn't support multiple runs of the same course. # as the Mongo modulestore doesn't support multiple runs of the same course.
...@@ -53,3 +56,10 @@ def rerun_course(source_course_key_string, destination_course_key_string, user_i ...@@ -53,3 +56,10 @@ def rerun_course(source_course_key_string, destination_course_key_string, user_i
pass pass
return "exception: " + unicode(exc) return "exception: " + unicode(exc)
def deserialize_fields(json_fields):
fields = json.loads(json_fields)
for field_name, value in fields.iteritems():
fields[field_name] = getattr(CourseFields, field_name).from_json(value)
return fields
...@@ -23,6 +23,7 @@ from xmodule.modulestore.django import modulestore ...@@ -23,6 +23,7 @@ from xmodule.modulestore.django import modulestore
from xmodule.contentstore.content import StaticContent from xmodule.contentstore.content import StaticContent
from xmodule.tabs import PDFTextbookTabs from xmodule.tabs import PDFTextbookTabs
from xmodule.partitions.partitions import UserPartition, Group from xmodule.partitions.partitions import UserPartition, Group
from xmodule.modulestore import EdxJSONEncoder
from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateCourseError from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateCourseError
from opaque_keys import InvalidKeyError from opaque_keys import InvalidKeyError
from opaque_keys.edx.locations import Location from opaque_keys.edx.locations import Location
...@@ -614,7 +615,8 @@ def _rerun_course(request, org, number, run, fields): ...@@ -614,7 +615,8 @@ def _rerun_course(request, org, number, run, fields):
CourseRerunState.objects.initiated(source_course_key, destination_course_key, request.user, fields['display_name']) CourseRerunState.objects.initiated(source_course_key, destination_course_key, request.user, fields['display_name'])
# Rerun the course as a new celery task # Rerun the course as a new celery task
rerun_course.delay(unicode(source_course_key), unicode(destination_course_key), request.user.id, fields) json_fields = json.dumps(fields, cls=EdxJSONEncoder)
rerun_course.delay(unicode(source_course_key), unicode(destination_course_key), request.user.id, json_fields)
# Return course listing page # Return course listing page
return JsonResponse({ return JsonResponse({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment