From e76083e7e9fc316474215a9a3f8859d46c0234ce Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Sun, 25 Dec 2011 12:47:29 -0500 Subject: [PATCH] Textbook, Preparing for randomized --- courseware/capa_module.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/courseware/capa_module.py b/courseware/capa_module.py index fe9f37ad83..e1b27b9000 100644 --- a/courseware/capa_module.py +++ b/courseware/capa_module.py @@ -110,6 +110,10 @@ class LoncapaModule(XModule): else: self.max_attempts=None + self.show_answer=node.getAttribute("showanswer") + if self.show_answer=="": + self.show_answer="closed" + if state!=None: state=json.loads(state) if state!=None and 'attempts' in state: @@ -131,10 +135,39 @@ class LoncapaModule(XModule): response = self.reset_problem(get) elif dispatch=='problem_save': response = self.save_problem(get) + elif dispatch=='get_answer': + response = self.get_answer(get) else: return "Error" return response + def answer_available(self): + ''' Is the user allowed to see an answer? + ''' + if self.show_answer == '': + return False + if self.show_answer == "never": + return False + if self.show_answer == 'attempted' and self.attempts == 0: + return False + if self.show_answer == 'attempted' and self.attempts > 0: + return True + if self.show_answer == 'answered' and self.lcp.done: + return True + if self.show_answer == 'answered' and not self.lcp.done: + return False + if self.show_answer == 'closed' and self.closed(): + return True + if self.show_answer == 'closed' and not self.closed(): + return False + raise Http404 + + def get_answer(self, get): + if not self.answer_available(): + raise Http404 + else: + raise Http404 + # Figure out if we should move these to capa_problem? def get_problem(self, get):