def evaluate(self, reply): """Check whether a suitable previous answer exists and return Boolean. :rtype: bool """ if self.summary_score: vals_to_be_tested = set( [self.summary_score.compute(reply.answer_set.all())['score']]) if self.previous_question: previous_answer = self.previous_question.previous_answer(reply) previous_answer = previous_answer and ast.literal_eval( previous_answer) flatlistofprevanswers = flatten([previous_answer]) vals_to_be_tested = set(flatlistofprevanswers) if self.values: valid_value_set = set(self.valid_values()) vals_to_be_tested = list(map(str, vals_to_be_tested)) return bool(not valid_value_set.isdisjoint(vals_to_be_tested)) if (self.more_than or self.less_than): inrange = lambda x: x > self.more_than and x < self.less_than return False not in list(map(inrange, vals_to_be_tested))
def as_markdown(self): """A helper to convert an asker and associated models to markdown format. :rtype: string """ _fields = "slug name steps_are_sequential redirect_url finish_on_last_page \ show_progress success_message step_navigation system_audio width".split() metayaml = yaml.safe_dump({i: getattr(self, i) for i in _fields}, default_flow_style=False) _pages_questions = [ (i.as_markdown(), [j.as_markdown() for j in i.get_questions()]) for i in self.askpage_set.all() ] qstrings = "\n\n".join(flatten(flatten(_pages_questions))) return "---\n" + metayaml + "---\n\n" + qstrings
def as_markdown(self): """A helper to convert an asker and associated models to markdown format. :rtype: string """ _fields = "slug name steps_are_sequential redirect_url finish_on_last_page \ show_progress success_message step_navigation system_audio width".split( ) metayaml = yaml.safe_dump({i: getattr(self, i) for i in _fields}, default_flow_style=False) _pages_questions = [(i.as_markdown(), [j.as_markdown() for j in i.get_questions()]) for i in self.askpage_set.all()] qstrings = "\n\n".join(flatten(flatten(_pages_questions))) return "---\n" + metayaml + "---\n\n" + qstrings
def evaluate(self, reply): """Check whether a suitable previous answer exists and return Boolean. :rtype: bool """ if self.summary_score: vals_to_be_tested = set([self.summary_score.compute(reply.answer_set.all())['score']]) if self.previous_question: previous_answer = self.previous_question.previous_answer(reply) previous_answer = previous_answer and ast.literal_eval(previous_answer) flatlistofprevanswers = flatten([previous_answer]) vals_to_be_tested = set(flatlistofprevanswers) if self.values: valid_value_set = set(self.valid_values()) vals_to_be_tested = map(str, vals_to_be_tested) return bool(not valid_value_set.isdisjoint(vals_to_be_tested)) if (self.more_than or self.less_than): inrange = lambda x: x > self.more_than and x < self.less_than return False not in map(inrange, vals_to_be_tested)