Commit 7f626e8a by Adam

Merge pull request #688 from edx/waheed/tnl1758-fix-training-example-answer-format-into-dict

Fixed training example answer format for old submissions.
parents 17d015d4 46d1141b
"""
Data Conversion utility methods for handling assessment data transformations.
"""
import json
def update_training_example_answer_format(answer):
"""
For each training example update 'answer' to newer format.
Args:
answer unicode string or dict
Returns:
dict
"""
if isinstance(answer, unicode) or isinstance(answer, str):
return {
'parts': [
{'text': answer}
]
}
return answer
...@@ -4,6 +4,7 @@ Serializers for the training assessment type. ...@@ -4,6 +4,7 @@ Serializers for the training assessment type.
from django.core.cache import cache from django.core.cache import cache
from django.db import transaction, IntegrityError from django.db import transaction, IntegrityError
from openassessment.assessment.models import TrainingExample from openassessment.assessment.models import TrainingExample
from openassessment.assessment.data_conversion import update_training_example_answer_format
from .base import rubric_from_dict, RubricSerializer from .base import rubric_from_dict, RubricSerializer
...@@ -58,7 +59,7 @@ def serialize_training_example(example): ...@@ -58,7 +59,7 @@ def serialize_training_example(example):
example_dict = cache.get(cache_key) example_dict = cache.get(cache_key)
if example_dict is None: if example_dict is None:
example_dict = { example_dict = {
'answer': example.answer, 'answer': update_training_example_answer_format(example.answer),
'options_selected': example.options_selected_dict, 'options_selected': example.options_selected_dict,
'rubric': RubricSerializer.serialized_from_cache(example.rubric), 'rubric': RubricSerializer.serialized_from_cache(example.rubric),
} }
......
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