From: Aleksander Ɓukasz Date: Thu, 7 Nov 2013 12:44:59 +0000 (+0100) Subject: Handle splitting field into parts in open questions X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/02f7bb229eac59214e8a5a8fe2f983a2bf1ab997?hp=7f9bc077404cdad084e4c77920ab17564d54ebec Handle splitting field into parts in open questions --- diff --git a/wtem/admin.py b/wtem/admin.py index a23874e..89389c1 100644 --- a/wtem/admin.py +++ b/wtem/admin.py @@ -38,7 +38,13 @@ def get_open_answer(answers, exercise): exercise_id = str(exercise['id']) answer = answers[exercise_id] if exercise['type'] == 'open': - toret = answer + if isinstance(answer, list): + toret = '' + for part in answer: + field = get_option(exercise['fields'], part['id']) + toret += '- %s:\n\n%s\n\n' % (field['caption'], part['text']) + else: + toret = answer if exercise['type'] == 'edumed_wybor': ok = set(map(str, exercise['answer'])) == set(map(str,answer['closed_part'])) toret = u'Czesc testowa [%s]:\n' % ('poprawna' if ok else 'niepoprawna') diff --git a/wtem/static/wtem/wtem.js b/wtem/static/wtem/wtem.js index 5253e03..7afbe0a 100644 --- a/wtem/static/wtem/wtem.js +++ b/wtem/static/wtem/wtem.js @@ -42,7 +42,18 @@ $(function() { }, open: function(el) { - push_answer(el, el.find('textarea').val()); + var textareas = el.find('textarea'), + to_push; + if(textareas.length === 1) { + to_push = el.find('textarea').val(); + } else { + to_push = []; + textareas.each(function() { + var textarea = $(this); + to_push.push({'id': textarea.attr('data-field-id'), 'text': textarea.val()}); + }); + } + push_answer(el, to_push); } } diff --git a/wtem/templates/wtem/exercises/open.html b/wtem/templates/wtem/exercises/open.html index 4d2c782..7572390 100644 --- a/wtem/templates/wtem/exercises/open.html +++ b/wtem/templates/wtem/exercises/open.html @@ -12,6 +12,27 @@ {% endautoescape %} - + {% if exercise.fields %} + {% for field in exercise.fields %} +
+ + +
+ {% endfor %} + {% else %} + + {% endif %} + + {% if exercise.description_after %} +
+ {% autoescape off %} + {% for para in exercise.description_after %} +

+ {{para}} +

+ {% endfor %} + {% endautoescape %} +
+ {% endif%} \ No newline at end of file diff --git a/wtem/templates/wtem/main.html b/wtem/templates/wtem/main.html index b3360b9..ccbae22 100644 --- a/wtem/templates/wtem/main.html +++ b/wtem/templates/wtem/main.html @@ -8,7 +8,14 @@ {% block body %} - +
{% csrf_token %}