diff --git a/BUGS.md b/BUGS.md index c9c9ed8..c60145b 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,7 +1,6 @@ # BUGS -- /review não mostra imagens porque precisa que teste esteja a decorrer... - usar thread.Lock para aceder a variaveis de estado? # TODO @@ -23,6 +22,7 @@ # FIXED +- /review não mostra imagens porque precisa que teste esteja a decorrer... - visualizar um teste ja realizado na página de administração - Depois da correcção, mostra testes realizados que não foram realizados pelo próprio - detectar se janela perde focus e alertar o prof (http://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active) diff --git a/app.py b/app.py index 3cb4f20..4018614 100644 --- a/app.py +++ b/app.py @@ -175,6 +175,8 @@ class App(object): return self.online[uid]['student']['name'] def get_test(self, uid, default=None): return self.online[uid].get('test', default) + def get_questions_path(self): + return self.testfactory['questions_dir'] def get_test_qtypes(self, uid): return {q['ref']:q['type'] for q in self.online[uid]['test']['questions']} def get_student_grades_from_all_tests(self, uid): diff --git a/serve.py b/serve.py index 63530b5..26fe2dd 100755 --- a/serve.py +++ b/serve.py @@ -256,6 +256,7 @@ class Root(object): @require() def file(self, ref, name): # serve a static file: userid, question ref, file name + # only works for users running a test uid = cherrypy.session.get(SESSION_KEY) filename = self.app.get_file(uid, ref, name) return cherrypy.lib.static.serve_file(filename) @@ -275,6 +276,12 @@ class Root(object): t = json.load(f) return self.template['review'].render(t=t) + @cherrypy.expose + @require(name_is('0')) + def absfile(self, name): + filename = path.abspath(path.join(self.app.get_questions_path(), name)) + return cherrypy.lib.static.serve_file(filename) + # ============================================================================ def parse_arguments(): argparser = argparse.ArgumentParser(description='Server for online tests. Enrolled students and tests have to be previously configured. Please read the documentation included with this software before running the server.') diff --git a/templates/review.html b/templates/review.html index c6e00b9..e0b22f1 100644 --- a/templates/review.html +++ b/templates/review.html @@ -89,7 +89,7 @@ <%! - from tools import md_to_html + from tools import md_to_html_review %> <% total_points = sum(q['points'] for q in t['questions']) @@ -105,7 +105,7 @@ ${q['title']}

- ${md_to_html(q['text'], q['ref'], q['files'])} + ${md_to_html_review(q['text'], q)}

% elif q['type'] == 'warning': @@ -115,7 +115,7 @@ ${q['title']}

- ${md_to_html(q['text'], q['ref'], q['files'])} + ${md_to_html_review(q['text'], q)}

% elif q['type'] == 'alert': @@ -125,7 +125,7 @@ ${q['title']}

- ${md_to_html(q['text'], q['ref'], q['files'])} + ${md_to_html_review(q['text'], q)}

@@ -146,15 +146,15 @@
- ${md_to_html(q['text'], q['ref'], q['files'])} + ${md_to_html_review(q['text'], q)}
% if q['type'] == 'radio': % for opt in q['options']: % if q['answer'] is not None and str(loop.index) == q['answer']: - ${md_to_html(' ' + opt, q['ref'], q['files'])} + ${md_to_html_review(' ' + opt, q)} % else: - ${md_to_html(' ' + opt, q['ref'], q['files'])} + ${md_to_html_review(' ' + opt, q)} % endif % endfor @@ -162,9 +162,9 @@ % elif q['type'] == 'checkbox': % for opt in q['options']: % if q['answer'] is not None and str(loop.index) in q['answer']: - ${md_to_html(' ' + opt, q['ref'], q['files'])} + ${md_to_html_review(' ' + opt, q)} % else: - ${md_to_html(' ' + opt, q['ref'], q['files'])} + ${md_to_html_review(' ' + opt, q)} % endif % endfor @@ -179,7 +179,7 @@
- ${md_to_html(q['hint'], q['ref'], q['files'])} + ${md_to_html_review(q['hint'], q)}
% endif # hint diff --git a/tools.py b/tools.py index 8ab4536..b72433a 100644 --- a/tools.py +++ b/tools.py @@ -1,5 +1,4 @@ - import subprocess import logging import yaml @@ -58,7 +57,9 @@ def run_script(script, stdin='', timeout=5): def md_to_html(text, ref=None, files={}): if ref is not None: - for k,f in files.items(): + # given q['ref'] and q['files'] replaces references to files by a + # GET to /file?ref=???;name=??? + for k in files: text = text.replace(k, '/file?ref={};name={}'.format(ref, k)) return markdown.markdown(text, extensions=[ 'markdown.extensions.tables', @@ -67,3 +68,14 @@ def md_to_html(text, ref=None, files={}): 'markdown.extensions.def_list', 'markdown.extensions.sane_lists' ]) + +def md_to_html_review(text, q): + for k,f in q['files'].items(): + text = text.replace(k, '/absfile?name={}'.format(q['files'][k])) + return markdown.markdown(text, extensions=[ + 'markdown.extensions.tables', + 'markdown.extensions.fenced_code', + 'markdown.extensions.codehilite', + 'markdown.extensions.def_list', + 'markdown.extensions.sane_lists' + ]) -- libgit2 0.21.2