Commit 2fff21e4eddbcb79a766b618cdf6ff489e57fdd8
1 parent
c68f0ced
Exists in
master
and in
1 other branch
- templates simplified using a base question and blocks for each type of answer.
Showing
6 changed files
with
72 additions
and
104 deletions
Show diff stats
serve.py
@@ -130,19 +130,9 @@ class LearnHandler(BaseHandler): | @@ -130,19 +130,9 @@ class LearnHandler(BaseHandler): | ||
130 | # ---------------------------------------------------------------------------- | 130 | # ---------------------------------------------------------------------------- |
131 | # respond to AJAX to get a JSON question | 131 | # respond to AJAX to get a JSON question |
132 | class QuestionHandler(BaseHandler): | 132 | class QuestionHandler(BaseHandler): |
133 | - # @tornado.web.authenticated | ||
134 | - # def get(self): | ||
135 | - # question = self.application.learn.next_question() | ||
136 | - # print('---> question.get') | ||
137 | - # print(question) | ||
138 | - # if question['type'] == 'checkbox': | ||
139 | - # self.render('question-checkbox.html', | ||
140 | - # question=question, | ||
141 | - # md=md, | ||
142 | - # ) | ||
143 | - | ||
144 | - # else: | ||
145 | - # self.write('Error!!!') | 133 | + @tornado.web.authenticated |
134 | + def get(self): | ||
135 | + self.redirect('/') | ||
146 | 136 | ||
147 | @tornado.web.authenticated | 137 | @tornado.web.authenticated |
148 | def post(self): | 138 | def post(self): |
@@ -189,12 +179,6 @@ class QuestionHandler(BaseHandler): | @@ -189,12 +179,6 @@ class QuestionHandler(BaseHandler): | ||
189 | 'correct': correct, | 179 | 'correct': correct, |
190 | }) | 180 | }) |
191 | 181 | ||
192 | - # if question['type'] == 'checkbox': | ||
193 | - # self.render('question-checkbox.html', | ||
194 | - # question=question, # the dictionary with the question?? | ||
195 | - # md=md, # passes function that renders markdown to html | ||
196 | - # ) | ||
197 | - | ||
198 | 182 | ||
199 | # ---------------------------------------------------------------------------- | 183 | # ---------------------------------------------------------------------------- |
200 | def main(): | 184 | def main(): |
templates/learn.html
@@ -100,7 +100,41 @@ $.fn.extend({ | @@ -100,7 +100,41 @@ $.fn.extend({ | ||
100 | } | 100 | } |
101 | }); | 101 | }); |
102 | 102 | ||
103 | +// function getCookie(name) { | ||
104 | +// var r = document.cookie.match("\\b" + name + "=([^;]*)\\b"); | ||
105 | +// return r ? r[1] : undefined; | ||
106 | +// } | ||
107 | + | ||
108 | +// jQuery.postJSON = function(url, args, callback) { | ||
109 | +// args._xsrf = getCookie("_xsrf"); | ||
110 | +// alert(args); | ||
111 | +// $.ajax({url: url, data: $.param(args), dataType: "text", type: "POST", | ||
112 | +// success: function(response) { | ||
113 | +// callback(eval("(" + response + ")")); | ||
114 | +// }}); | ||
115 | +// } | ||
116 | + | ||
103 | function getQuestion() { | 117 | function getQuestion() { |
118 | + // var data = $("#question_form").serialize(); | ||
119 | + // $.postJSON('/question', data, function(response){ | ||
120 | + // $("#question_div").html(response["html"]); | ||
121 | + // MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question"]); | ||
122 | + | ||
123 | + // if (response["correct"]) { | ||
124 | + // $('#question_div').animateCSS('pulse'); | ||
125 | + // } | ||
126 | + // else { | ||
127 | + // $('#question_div').animateCSS('shake'); | ||
128 | + // } | ||
129 | + | ||
130 | + // $("input:text").bind("keypress", function (e) { | ||
131 | + // if (e.keyCode == 13) { | ||
132 | + // e.preventDefault(); | ||
133 | + // getQuestion(); | ||
134 | + // } | ||
135 | + // }); | ||
136 | + // }); | ||
137 | + | ||
104 | $.ajax({ | 138 | $.ajax({ |
105 | type: "POST", | 139 | type: "POST", |
106 | url: "/question", | 140 | url: "/question", |
templates/question-checkbox.html
1 | +{% extends "question.html" %} | ||
1 | {% autoescape %} | 2 | {% autoescape %} |
2 | 3 | ||
3 | -<div class="panel panel-default"> | ||
4 | - <div class="panel-heading"> | ||
5 | - <!-- <h3 id="title"> --> | ||
6 | - {{ question['title'] }} | ||
7 | - <!-- </h3> --> | 4 | +{% block answer %} |
5 | +<fieldset data-role="controlgroup"> | ||
6 | + <div class="list-group"> | ||
7 | + {% for n,opt in enumerate(question['options']) %} | ||
8 | + <a class="list-group-item"> | ||
9 | + <input type="checkbox" id="{{ n }}" name="answer" value="{{ n }}"> | ||
10 | + {{ opt }} | ||
11 | + </a> | ||
12 | + {% end %} | ||
8 | </div> | 13 | </div> |
9 | - <div class="panel-body"> | ||
10 | - | ||
11 | - <div id="text"> | ||
12 | - {{ md(question['text']) }} | ||
13 | - </div> | ||
14 | - | ||
15 | - <fieldset data-role="controlgroup"> | ||
16 | - <div class="list-group"> | ||
17 | - {% for n,opt in enumerate(question['options']) %} | ||
18 | - <a class="list-group-item"> | ||
19 | - <input type="checkbox" id="{{ n }}" name="answer" value="{{ n }}"> | ||
20 | - {{ opt }} | ||
21 | - </a> | ||
22 | - {% end %} | ||
23 | - </div> | ||
24 | - </fieldset> | ||
25 | - </div> | ||
26 | -</div> | 14 | +</fieldset> |
15 | +{% end %} | ||
27 | \ No newline at end of file | 16 | \ No newline at end of file |
templates/question-radio.html
1 | +{% extends "question.html" %} | ||
1 | {% autoescape %} | 2 | {% autoescape %} |
2 | 3 | ||
3 | -<div class="panel panel-default"> | ||
4 | - <div class="panel-heading"> | ||
5 | - <!-- <h3 id="title"> --> | ||
6 | - {{ question['title'] }} | ||
7 | - <!-- </h3> --> | 4 | +{% block answer %} |
5 | +<fieldset data-role="controlgroup"> | ||
6 | + <div class="list-group"> | ||
7 | + {% for n,opt in enumerate(question['options']) %} | ||
8 | + <a class="list-group-item"> | ||
9 | + <input type="radio" id="{{ n }}" name="answer" value="{{ n }}"> | ||
10 | + {{ md(opt) }} | ||
11 | + </a> | ||
12 | + {% end %} | ||
8 | </div> | 13 | </div> |
9 | - | ||
10 | - <div class="panel-body"> | ||
11 | - | ||
12 | - <div id="text"> | ||
13 | - {{ md(question['text']) }} | ||
14 | - </div> | ||
15 | - | ||
16 | - <fieldset data-role="controlgroup"> | ||
17 | - <div class="list-group"> | ||
18 | - {% for n,opt in enumerate(question['options']) %} | ||
19 | - <a class="list-group-item"> | ||
20 | - <input type="radio" id="{{ n }}" name="answer" value="{{ n }}"> | ||
21 | - {{ md(opt) }} | ||
22 | - </a> | ||
23 | - {% end %} | ||
24 | - </div> | ||
25 | - </fieldset> | ||
26 | - | ||
27 | - </div> | ||
28 | -</div> | ||
29 | \ No newline at end of file | 14 | \ No newline at end of file |
15 | +</fieldset> | ||
16 | +{% end %} | ||
30 | \ No newline at end of file | 17 | \ No newline at end of file |
templates/question-text.html
1 | -{% autoescape %} | 1 | +{% extends "question.html" %} |
2 | 2 | ||
3 | - | ||
4 | -<div class="panel panel-default"> | ||
5 | - <div class="panel-heading"> | ||
6 | - <!-- <h3 id="title"> --> | ||
7 | - {{ question['title'] }} | ||
8 | - <!-- </h3> --> | ||
9 | - </div> | ||
10 | - | ||
11 | - <div class="panel-body"> | ||
12 | - | ||
13 | - <div id="text"> | ||
14 | - {{ md(question['text']) }} | ||
15 | - </div> | ||
16 | - | ||
17 | - <fieldset data-role="controlgroup"> | ||
18 | - <input type="text" class="form-control" id="answer" name="answer" value=""> | ||
19 | - </fieldset> | ||
20 | - </div> | ||
21 | -</div> | 3 | +{% block answer %} |
4 | +<fieldset data-role="controlgroup"> | ||
5 | + <input type="text" class="form-control" id="answer" name="answer" value=""> | ||
6 | +</fieldset> | ||
7 | +{% end %} | ||
22 | \ No newline at end of file | 8 | \ No newline at end of file |
templates/question-textarea.html
1 | +{% extends "question.html" %} | ||
1 | {% autoescape %} | 2 | {% autoescape %} |
2 | 3 | ||
3 | - | ||
4 | -<div class="panel panel-default"> | ||
5 | - <div class="panel-heading"> | ||
6 | - <!-- <h3 id="title"> --> | ||
7 | - {{ question['title'] }} | ||
8 | - <!-- </h3> --> | ||
9 | - </div> | ||
10 | - | ||
11 | - <div class="panel-body"> | ||
12 | - <div id="text"> | ||
13 | - {{ md(question['text']) }} | ||
14 | - </div> | ||
15 | - | ||
16 | - <textarea class="form-control" rows="{{ question['lines'] }}" name="answer"></textarea><br /> | ||
17 | - <input type="hidden" name="question_ref" value="{{ question['ref'] }}"> | ||
18 | - </div> | ||
19 | -</div> | 4 | +{% block answer %} |
5 | +<textarea class="form-control" rows="{{ question['lines'] }}" name="answer"></textarea><br /> | ||
6 | +<input type="hidden" name="question_ref" value="{{ question['ref'] }}"> | ||
7 | +{% end %} | ||
20 | \ No newline at end of file | 8 | \ No newline at end of file |