Handle splitting field into parts in open questions
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 7 Nov 2013 12:44:59 +0000 (13:44 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 15 Jan 2014 10:18:56 +0000 (11:18 +0100)
wtem/admin.py
wtem/static/wtem/wtem.js
wtem/templates/wtem/exercises/open.html
wtem/templates/wtem/main.html

index a23874e..89389c1 100644 (file)
@@ -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')
index 5253e03..7afbe0a 100644 (file)
@@ -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);
         }
     }
 
index 4d2c782..7572390 100644 (file)
         {% endautoescape %}
     </div>
 
-    <textarea style="width: 100%; margin-top:10px;" rows="10"></textarea>
+    {% if exercise.fields %}
+        {% for field in exercise.fields %}
+            <div class="wtem-open-field">
+                <label class="wtem-caption">{{field.caption}}</label>
+                <textarea style="width: 100%;" rows="10" data-field-id="{{field.id}}"></textarea>
+            </div>
+        {% endfor %}
+    {% else %}
+        <textarea style="width: 100%; margin-top:10px;" rows="10"></textarea>
+    {% endif %}
+
+    {% if exercise.description_after %}
+        <div class="description">
+            {% autoescape off %}
+            {% for para in exercise.description_after %}
+                <p class="paragraph">
+                    {{para}}
+                </p>
+            {% endfor %}
+            {% endautoescape %}
+        </div>
+    {% endif%}
 
 </div>
\ No newline at end of file
index b3360b9..ccbae22 100644 (file)
@@ -8,7 +8,14 @@
 
 
 {% block body %}
-
+<style>
+    .wtem-open-field {
+        margin: 10px 0;
+    }
+    .wtem-open-field textarea {
+        margin-top:0;
+    }
+</style>
 <form method="post" enctype="multipart/form-data">
 {% csrf_token %}