def show_audit_list(self, instance): show = AuditListPop() show.title = "Related completed audits for the question: " + instance.text + " from " + instance.audit_title audit_list = list( CompletedAudit.objects(title=instance.audit_title, severity=Severity.red())) self.populate_audit_list_pop(audit_list, show, instance.text, show) show.open()
def grab_audits_with_title(self, title): audits_with_title = [] for audit in list(CompletedAudit.objects()): if difflib.get_close_matches(title.lower(), [audit.title.lower()]): audits_with_title.append(audit) return audits_with_title
def resolve_submit(self): audit_to_resolve = CompletedAudit.objects() \ .filter(title=self.resolve_button.title, auditor=self.resolve_button.auditor, datetime=self.resolve_button.datetime) \ .get(title=self.resolve_button.title, auditor=self.resolve_button.auditor, datetime=self.resolve_button.datetime) # Remove string label, which has 17 chars as defined in CompletedAuditPage.add_question_answer audit_answer_to_resolve = audit_to_resolve.answers.filter(text=self.question_text[17:]) \ .get(text=self.question_text[17:]) audit_answer_to_resolve.resolved = True audit_to_resolve.unresolved_count -= 1 audit_to_resolve.save() self.remove_widget(self.resolve_button)
def retrieve_flagged_answers(self): self.unique_entry_rows = [] completed_audits = list( CompletedAudit.objects(severity=Severity.red())) # Go over each flagged answer and append them to a local 3d-array while counting the number of repeated flags for audit in completed_audits: for answer in audit.answers: if answer.severity == Severity.red(): is_unique_row = True for entry_row in self.unique_entry_rows: if entry_row[0] == audit.title and entry_row[ 1] == answer.text: entry_row[2] += 1 is_unique_row = False break if is_unique_row: self.unique_entry_rows.append( [audit.title, answer.text, 1]) # Default Sort self.sort_by_times_flagged()
def test_storage_and_retrieval(self): title = "Boiler Room Shenanigans" auditor = "Erik The Auditor" a0_text = "Did you stick your head in the boiler?" a0_severity = Severity.red() a0_response = Response.yes() a1_text = "Was there dust on the machine?" a1_severity = Severity.yellow() a1_response = Response.no() a2_text = "Did you clean the machine?" a2_severity = Severity.green() a2_response = Response.other() a2_comment = "There was no dust on the machine to clean." CompletedAuditBuilder() \ .with_title(title) \ .with_auditor(auditor) \ .with_answer( Answer( text=a0_text, severity=a0_severity, response=a0_response, ) ).with_answer( Answer( text=a1_text, severity=a1_severity, response=a1_response, ) ).with_answer( Answer( text=a2_text, severity=a2_severity, response=a2_response, comment=a2_comment, ) ).build().save() audits = CompletedAudit.objects(title=title) self.assertEqual(title, audits[0].title) self.assertEqual(1, len(audits)) self.assertEqual(3, len(audits[0].answers)) audit = audits[0] a0_text = "Did you stick your head in the boiler?" a0_severity = Severity.red() a0_response = Response.yes() a1_text = "Was there dust on the machine?" a1_severity = Severity.yellow() a1_response = Response.no() a2_text = "Did you clean the machine?" a2_severity = Severity.green() a2_response = Response.other() a2_comment = "There was no dust on the machine to clean." self.assertEqual(a0_text, audit.answers[0].text) self.assertEqual(a0_severity, audit.answers[0].severity) self.assertEqual(a0_response, audit.answers[0].response) self.assertEqual(None, audit.answers[0].comment) self.assertEqual(a1_text, audit.answers[1].text) self.assertEqual(a1_severity, audit.answers[1].severity) self.assertEqual(a1_response, audit.answers[1].response) self.assertEqual(None, audit.answers[1].comment) self.assertEqual(a2_text, audit.answers[2].text) self.assertEqual(a2_severity, audit.answers[2].severity) self.assertEqual(a2_response, audit.answers[2].response) self.assertEqual(a2_comment, audit.answers[2].comment) self.assertGreaterEqual(datetime.utcnow(), audit.datetime)
def load_audit_template_and_completed_audit_with_title_and_datetime(self, dt): ca = list(CompletedAudit.objects(datetime=dt)) return ca[0]
def get_completed_audit(self): ca_list = list(CompletedAudit.objects(datetime=self.dt_obj)) return ca_list[0]
def load_completed_audits(self): self.audits = list(CompletedAudit.objects().only( "title", "datetime", "auditor", "severity", "unresolved_count")) self.sort_by_severity() self.refresh_completed_audits()
def load_completed_audits(self): self.audits = list(CompletedAudit.objects().only( "title", "datetime", "auditor")) self.sort_by_date() self.refresh_completed_audits()