From: Aleksander Łukasz Date: Wed, 30 Oct 2013 15:52:44 +0000 (+0100) Subject: wip: showing first couple of questions X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/ee9eaab760964d7a27aefdaf9c9ee5379f680994 wip: showing first couple of questions --- diff --git a/edumed/settings.d/50-static.py b/edumed/settings.d/50-static.py index 35aabe2..5b6c079 100644 --- a/edumed/settings.d/50-static.py +++ b/edumed/settings.d/50-static.py @@ -51,6 +51,7 @@ PIPELINE_JS = { 'wtem': { 'source_filenames': ( 'wtem/edumed.js', + 'wtem/wtem.js', ), 'output_filename': 'compressed/wtem.js' }, diff --git a/wtem/static/wtem/edumed.coffee b/wtem/static/wtem/edumed.coffee index fb8ea87..baae08e 100644 --- a/wtem/static/wtem/edumed.coffee +++ b/wtem/static/wtem/edumed.coffee @@ -67,6 +67,12 @@ class Exercise extends Binding $(".question", @element).each (i, question) => @solve_question question + get_answers: -> + answers = [] + $('.question', @element).each (i, question) => + answers.push(@get_answer question) + return answers + # Parses a list of values, separated by space or comma. # The list is read from data attribute of elem using data_key # Returns a list with elements @@ -243,6 +249,13 @@ class Wybor extends Exercise console.log("check " + $("input[type=checkbox]", qpiece).attr("id") + " -> " + should_be_checked) $("input[type=checkbox],input[type=radio]", qpiece).prop 'checked', should_be_checked + get_answer: (question) -> + answer = [] + $('.question-piece', question).each (i, qpiece) => + $qpiece = $(qpiece) + if $("input[type=checkbox],input[type=radio]", qpiece).is(':checked') + answer.push($qpiece.attr('data-name')) + return answer class Uporzadkuj extends Exercise diff --git a/wtem/static/wtem/edumed.js b/wtem/static/wtem/edumed.js index f828dec..58b5114 100644 --- a/wtem/static/wtem/edumed.js +++ b/wtem/static/wtem/edumed.js @@ -95,6 +95,16 @@ }); }; + Exercise.prototype.get_answers = function() { + var answers, + _this = this; + answers = []; + $('.question', this.element).each(function(i, question) { + return answers.push(_this.get_answer(question)); + }); + return answers; + }; + Exercise.prototype.get_value_list = function(elem, data_key, numbers) { var vl; vl = $(elem).attr("data-" + data_key).split(/[ ,]+/).map($.trim); @@ -286,6 +296,20 @@ }); }; + Wybor.prototype.get_answer = function(question) { + var answer, + _this = this; + answer = []; + $('.question-piece', question).each(function(i, qpiece) { + var $qpiece; + $qpiece = $(qpiece); + if ($("input[type=checkbox],input[type=radio]", qpiece).is(':checked')) { + return answer.push($qpiece.attr('data-name')); + } + }); + return answer; + }; + return Wybor; })(Exercise); diff --git a/wtem/static/wtem/wtem.js b/wtem/static/wtem/wtem.js new file mode 100644 index 0000000..f87ad42 --- /dev/null +++ b/wtem/static/wtem/wtem.js @@ -0,0 +1,14 @@ +$(function() { + + $('#submit_answers').click(function() { + var to_submit = []; + $('.exercise').each(function() { + var exercise = $(this).data('exercise'); + if(exercise.get_answers) { + to_submit.push(exercise.get_answers()[0]); + } + }); + console.log(JSON.stringify(to_submit)); + }); + +}); \ No newline at end of file diff --git a/wtem/templates/wtem/exercises/edumed_wybor.html b/wtem/templates/wtem/exercises/edumed_wybor.html new file mode 100644 index 0000000..511cf7f --- /dev/null +++ b/wtem/templates/wtem/exercises/edumed_wybor.html @@ -0,0 +1,22 @@ +
+ +

Zadanie {{no}}

+ +
+

+ {{exercise.description}} +

+
+ +
+
    + {% for option in exercise.options %} +
  1. + + +
  2. + {% endfor %} +
+
+ +
\ No newline at end of file diff --git a/wtem/templates/wtem/main.html b/wtem/templates/wtem/main.html index bee75ec..ccb6023 100644 --- a/wtem/templates/wtem/main.html +++ b/wtem/templates/wtem/main.html @@ -4,3 +4,19 @@ {% block extra_script %} {% compressed_js 'wtem' %} {% endblock %} + + + +{% block body %} + +{% for exercise in exercises %} + {% with 'wtem/exercises/'|add:exercise.type|add:'.html' as template_name %} + {% include template_name with exercise=exercise no=forloop.counter %} + {% endwith %} +{% endfor %} + + +
+ + +{% endblock %} \ No newline at end of file diff --git a/wtem/views.py b/wtem/views.py index ae1f64b..6578e44 100644 --- a/wtem/views.py +++ b/wtem/views.py @@ -1,4 +1,13 @@ +import os + from django.shortcuts import render +from django.utils import simplejson + def main(request): - return render(request, 'wtem/main.html') \ No newline at end of file + ## @@ move this out of the view + f = file(os.path.dirname(__file__) + '/fixtures/exercises.json') + exercises = simplejson.loads(f.read()) + f.close() + + return render(request, 'wtem/main.html', dict(exercises = exercises))