Commit 3d24dd0fb7fc8416ff0a151889991c16819112a1

Authored by Miguel Barão
1 parent 73e9fbcb
Exists in master and in 1 other branch dev

- configuration of logger system to support --debug

Showing 3 changed files with 20 additions and 51 deletions   Show diff stats
1 1
2 # BUGS 2 # BUGS
3 3
4 -- total do teste aparece negativo.  
5 -- espaco no final das tabelas.  
6 - qual a diferenca entre md_to_html e md_to_html_review, parece desnecessario haver dois. 4 - qual a diferenca entre md_to_html e md_to_html_review, parece desnecessario haver dois.
7 - servir imagens das perguntas 5 - servir imagens das perguntas
8 -- como alterar configuracao para mostrar logs de debug?  
9 - hints nao funciona 6 - hints nao funciona
10 - uniformizar question.py com a de aprendizations... 7 - uniformizar question.py com a de aprendizations...
11 -- permitir eliminar teste a decorrer de modo a que o aluno possa recomeçar (e.g. noutro browser) 8 +- permitir eliminar teste a decorrer
12 - servidor nao esta a lidar com eventos scroll/resize. ignorar? 9 - servidor nao esta a lidar com eventos scroll/resize. ignorar?
13 10
14 # TODO 11 # TODO
@@ -20,6 +17,8 @@ @@ -20,6 +17,8 @@
20 npm install mathjax-node mathjax-node-cli # pacotes em ~/node_modules 17 npm install mathjax-node mathjax-node-cli # pacotes em ~/node_modules
21 node_modules/mathjax-node-cli/bin/tex2svg '\sqrt{x}' 18 node_modules/mathjax-node-cli/bin/tex2svg '\sqrt{x}'
22 usar isto para gerar svg que passa a fazer parte do texto da pergunta (markdown suporta tags svg?) 19 usar isto para gerar svg que passa a fazer parte do texto da pergunta (markdown suporta tags svg?)
  20 + fazer funçao tex() que recebe formula e converte para svg. exemplo:
  21 + fr'''A formula é {tex(\sqrt{x]})}'''
23 22
24 - Gerar pdf's com todos os testes no final (pdfkit). 23 - Gerar pdf's com todos os testes no final (pdfkit).
25 - manter registo dos unfocus durante o teste e de qual a pergunta visivel nesse momento 24 - manter registo dos unfocus durante o teste e de qual a pergunta visivel nesse momento
@@ -37,6 +36,9 @@ @@ -37,6 +36,9 @@
37 36
38 # FIXED 37 # FIXED
39 38
  39 +- como alterar configuracao para mostrar logs de debug?
  40 +- espaco no final das tabelas.
  41 +- total do teste aparece negativo.
40 - reset password nao funciona no admin 42 - reset password nao funciona no admin
41 - reload a intervalos não funciona. 43 - reload a intervalos não funciona.
42 - allow/deny nao funciona no /admin. 44 - allow/deny nao funciona no /admin.
config/server.conf
@@ -1,21 +0,0 @@ @@ -1,21 +0,0 @@
1 -# -*- coding: utf-8 -*-  
2 -  
3 -[global]  
4 -environment= 'production'  
5 -  
6 -; number of threads running  
7 -server.thread_pool= 10  
8 -  
9 -; Host address and port  
10 -; set socket_port = 443 if SSL is enabled below, 8080 otherwise  
11 -; if port is 443 then the server should be run as root. SSL also works on 8080.  
12 -server.socket_host = '0.0.0.0'  
13 -server.socket_port = 8080  
14 -  
15 -; Uncomment to enable SSL (ssl_module = 'builtin' or 'pyopenssl')  
16 -; server.ssl_module = 'builtin'  
17 -; server.ssl_certificate = 'certs/webserver.crt'  
18 -; server.ssl_private_key = 'certs/webserver.key'  
19 -  
20 -; not required for snakeoil:  
21 -; server.ssl_certificate_chain = 'ca_certs.crt'  
@@ -59,6 +59,7 @@ class BaseHandler(tornado.web.RequestHandler): @@ -59,6 +59,7 @@ class BaseHandler(tornado.web.RequestHandler):
59 if cookie: 59 if cookie:
60 return cookie.decode('utf-8') 60 return cookie.decode('utf-8')
61 61
  62 +
62 # ------------------------------------------------------------------------- 63 # -------------------------------------------------------------------------
63 # /login and /logout 64 # /login and /logout
64 # ------------------------------------------------------------------------- 65 # -------------------------------------------------------------------------
@@ -75,7 +76,9 @@ class LoginHandler(BaseHandler): @@ -75,7 +76,9 @@ class LoginHandler(BaseHandler):
75 self.set_secure_cookie("user", str(uid), expires_days=30) 76 self.set_secure_cookie("user", str(uid), expires_days=30)
76 self.redirect(self.get_argument("next", "/")) 77 self.redirect(self.get_argument("next", "/"))
77 else: 78 else:
78 - self.render("login.html", error='Não autorizado ou número/senha inválido') 79 + self.render("login.html",
  80 + error='Não autorizado ou número/senha inválido')
  81 +
79 82
80 # ------------------------------------------------------------------------- 83 # -------------------------------------------------------------------------
81 class LogoutHandler(BaseHandler): 84 class LogoutHandler(BaseHandler):
@@ -85,6 +88,7 @@ class LogoutHandler(BaseHandler): @@ -85,6 +88,7 @@ class LogoutHandler(BaseHandler):
85 self.clear_cookie('user') 88 self.clear_cookie('user')
86 self.redirect('/') 89 self.redirect('/')
87 90
  91 +
88 # ------------------------------------------------------------------------- 92 # -------------------------------------------------------------------------
89 # FIXME checkit 93 # FIXME checkit
90 class FileHandler(BaseHandler): 94 class FileHandler(BaseHandler):
@@ -101,6 +105,7 @@ class FileHandler(BaseHandler): @@ -101,6 +105,7 @@ class FileHandler(BaseHandler):
101 self.write(f.read()) 105 self.write(f.read())
102 f.close() 106 f.close()
103 107
  108 +
104 # ------------------------------------------------------------------------- 109 # -------------------------------------------------------------------------
105 # FIXME images missing, needs testing 110 # FIXME images missing, needs testing
106 # ------------------------------------------------------------------------- 111 # -------------------------------------------------------------------------
@@ -128,7 +133,6 @@ class TestHandler(BaseHandler): @@ -128,7 +133,6 @@ class TestHandler(BaseHandler):
128 t = self.testapp.get_test(uid) or self.testapp.generate_test(uid) 133 t = self.testapp.get_test(uid) or self.testapp.generate_test(uid)
129 self.render('test.html', t=t, md=md_to_html, templ=self.templates) 134 self.render('test.html', t=t, md=md_to_html, templ=self.templates)
130 135
131 -  
132 # POST 136 # POST
133 @tornado.web.authenticated 137 @tornado.web.authenticated
134 def post(self): 138 def post(self):
@@ -150,7 +154,8 @@ class TestHandler(BaseHandler): @@ -150,7 +154,8 @@ class TestHandler(BaseHandler):
150 ans[i] = None 154 ans[i] = None
151 else: 155 else:
152 ans[i] = ans[i][0] 156 ans[i] = ans[i][0]
153 - elif q['type'] in ('text', 'text-regex', 'textarea', 'numeric-interval'): 157 + elif q['type'] in ('text', 'text-regex', 'textarea',
  158 + 'numeric-interval'):
154 ans[i] = ans[i][0] 159 ans[i] = ans[i][0]
155 160
156 self.testapp.correct_test(uid, ans) 161 self.testapp.correct_test(uid, ans)
@@ -235,9 +240,8 @@ class RootHandler(BaseHandler): @@ -235,9 +240,8 @@ class RootHandler(BaseHandler):
235 self.redirect('/test') 240 self.redirect('/test')
236 241
237 242
238 -# ---------------------------------------------------------------------------- 243 +# -------------------------------------------------------------------------
239 class AdminHandler(BaseHandler): 244 class AdminHandler(BaseHandler):
240 -  
241 @tornado.web.authenticated 245 @tornado.web.authenticated
242 def get(self): 246 def get(self):
243 if self.current_user != '0': 247 if self.current_user != '0':
@@ -264,7 +268,6 @@ class AdminHandler(BaseHandler): @@ -264,7 +268,6 @@ class AdminHandler(BaseHandler):
264 else: 268 else:
265 self.render('admin.html') 269 self.render('admin.html')
266 270
267 -  
268 @tornado.web.authenticated 271 @tornado.web.authenticated
269 def post(self): 272 def post(self):
270 if self.current_user != '0': 273 if self.current_user != '0':
@@ -290,28 +293,10 @@ class AdminHandler(BaseHandler): @@ -290,28 +293,10 @@ class AdminHandler(BaseHandler):
290 logging.error(f'Unknown command in post: "{cmd}"') 293 logging.error(f'Unknown command in post: "{cmd}"')
291 294
292 295
293 -  
294 -# # ============================================================================  
295 -# # Student webservice  
296 -# # ============================================================================  
297 -# class StudentWebService(object):  
298 -  
299 -# @cherrypy.tools.accept(media='application/json') # FIXME  
300 -# def POST(self, **args):  
301 -# # uid = cherrypy.session.get(SESSION_KEY)  
302 -# if args['cmd'] == 'focus':  
303 -# v = json.loads(args['value'])  
304 -# self.app.set_student_focus(uid=args['number'], value=v)  
305 -  
306 -  
307 -  
308 # ------------------------------------------------------------------------- 296 # -------------------------------------------------------------------------
309 # Tornado web server 297 # Tornado web server
310 # ------------------------------------------------------------------------- 298 # -------------------------------------------------------------------------
311 def main(): 299 def main():
312 - SERVER_PATH = path.dirname(path.realpath(__file__))  
313 - LOGGER_CONF = path.join(SERVER_PATH, 'config/logger.yaml')  
314 -  
315 # --- Commandline argument parsing 300 # --- Commandline argument parsing
316 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.') 301 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.')
317 argparser.add_argument('--debug', action='store_true', 302 argparser.add_argument('--debug', action='store_true',
@@ -321,6 +306,10 @@ def main(): @@ -321,6 +306,10 @@ def main():
321 arg = argparser.parse_args() 306 arg = argparser.parse_args()
322 307
323 # --- Setup logging 308 # --- Setup logging
  309 + logger_file = 'logger-debug.yaml' if arg.debug else 'logger.yaml'
  310 + SERVER_PATH = path.dirname(path.realpath(__file__))
  311 + LOGGER_CONF = path.join(SERVER_PATH, f'config/{logger_file}')
  312 +
324 try: 313 try:
325 logging.config.dictConfig(load_yaml(LOGGER_CONF)) 314 logging.config.dictConfig(load_yaml(LOGGER_CONF))
326 except: 315 except:
@@ -349,7 +338,7 @@ def main(): @@ -349,7 +338,7 @@ def main():
349 ssl_options={ 338 ssl_options={
350 "certfile": "certs/cert.crt", 339 "certfile": "certs/cert.crt",
351 "keyfile": "certs/cert.key" 340 "keyfile": "certs/cert.key"
352 - }) 341 + })
353 http_server.listen(8443) 342 http_server.listen(8443)
354 343
355 # --- run webserver 344 # --- run webserver
@@ -365,4 +354,3 @@ def main(): @@ -365,4 +354,3 @@ def main():
365 # ------------------------------------------------------------------------- 354 # -------------------------------------------------------------------------
366 if __name__ == "__main__": 355 if __name__ == "__main__":
367 main() 356 main()
368 -