From e8e0e93719cf276d1d3df6b47c53f30c5ad83ac8 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 24 Feb 2016 13:15:31 +0100 Subject: Merge hint function into test for {Prolog,Python}Session --- server/python_session.py | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) (limited to 'server/python_session.py') diff --git a/server/python_session.py b/server/python_session.py index 555a55f..9ceda9b 100644 --- a/server/python_session.py +++ b/server/python_session.py @@ -97,42 +97,31 @@ class PythonSession(server.LanguageSession): def __del__(self): self.destroy() + # TODO remove this def hint(self, sid, problem_id, program): - p = Problem.get(id=problem_id) - language_module = server.problems.load_language(p.language, 'common') - problem_module = server.problems.load_problem(p.language, p.group, p.identifier, 'common') - - hints = [] - # check if the program is already correct - passed, _ = problem_module.test(self.run, program) - if passed: - hints = [{'id': 'program_already_correct'}] - - if not hints and hasattr(language_module, 'hint'): - hints = language_module.hint(self.run, program) - if not hints and hasattr(problem_module, 'hint'): - hints = problem_module.hint(self.run, program) - if not hints: - hints = [{'id': 'no_hint'}] - - self._instantiate_and_save_hints(language_module, problem_module, hints) - return hints + return [] def test(self, sid, problem_id, program): p = Problem.get(id=problem_id) language_module = server.problems.load_language(p.language, 'common') problem_module = server.problems.load_problem(p.language, p.group, p.identifier, 'common') - try: - passed, hints = problem_module.test(self.run, program) - if passed: - session = server.user_session.get_session_by_id(sid) - session.update_solution(problem_id, done=True) - except AttributeError as ex: - hints = [{'id': 'system_error', 'args': {'message': 'test function does not exist'}}] - - self._instantiate_and_save_hints(language_module, problem_module, hints) - return hints + # check if the program is correct + passed, msgs = problem_module.test(self.run, program) + if passed: + session = server.user_session.get_session_by_id(sid) + session.update_solution(problem_id, done=True) + else: + hints = [] + if not hints and hasattr(language_module, 'hint'): + hints = language_module.hint(self.run, program) + if not hints and hasattr(problem_module, 'hint'): + hints = problem_module.hint(self.run, program) + if hints: + msgs.extend(hints) + + self._instantiate_and_save_hints(language_module, problem_module, msgs) + return msgs # Add hint parameters (such as message index) based on hint class. Append # the finalized hints to the list of sent hints. -- cgit v1.2.1