def loadSurvey(filename): from question import Question from answer import Answer survey = None f = open(filename, "r") if f is not None: s = "" b = f.read(512) while len(b): s += b b = f.read(512) f.close() sd = jsonpickle.decode(s) survey = Survey() survey.name = sd['name'] survey.questions = {} for qd in sd['questions'].values(): question = Question() question.id = qd['id'] question.name = qd['name'] question.answers = {} for ad in qd['answers'].values(): answer = Answer() answer.id = ad['id'] answer.value = ad['value'] answer.selected = ad['selected'] answer.editable = ad['editable'] question.answers[answer.id] = answer survey.questions[question.id] = question return survey
def test_delete_is_working(self): with DB() as database: question = Question().create() question.id = database.execute('''SELECT id FROM questions WHERE question = ?''', \ (question.question,)).fetchone()[0] with DB() as database: question.delete() self.assertEqual(Question.find(question.id), None)
def test_update_is_working(self): with DB() as database: question = Question().create() question.id = database.execute('''SELECT id FROM questions WHERE question = ?''', \ (question.question,)).fetchone()[0] with DB() as database: question.update(["NewQuestion", question.correct_answer], question.answers).edit() self.assertEqual(Question.find(question.id), question) # find Question with id question id
def display_question(quiz, next): global quizname #display question #id = 0 #prompt = u'' #response = u'' #imgfn = u'' #sndfn = u'' #map = u'' global dquiz, dnext global prompt_id global response_id global work global q dquiz = quiz dnext = next print 'display_question', quizname, len(quiz), next if next < len(quiz): q = quiz[next] else: q = Question() q.id = -1 #don't add question to db before needed q.prompt = '' q.response = '' q.imgfn = '' q.sndfn = '' q.map = '' q.answer_link = '' print 'q is', q.id, ':', q.prompt, ':', q.response, ':', q.imgfn, ':', q.sndfn, ':', q.map #we need a working copy of the question to support undo work = Question() work.prompt = q.prompt work.response = q.response work.id = q.id work.imgfn = q.imgfn work.sndfn = q.sndfn work.map = q.map display_page()
def process_question_items(content): """ Process response and generate dictionary with questions and URL :param content: :return: """ questions = list() if "items" in content: items = content["items"] for item in items: question = Question() question.id = item['question_id'] question.title = item['title'] question.link = item['link'] question.tags = item['tags'] question.is_answered = item['is_answered'] question.answer_count = item['answer_count'] questions.append(question) return questions
def makebundle(quiz_id): q = "SELECT text FROM categories WHERE id = '%i'" % quiz_id res = __SERVICES__.db.query(q) quizname = res[0][0] create_empty_folder(BUNDLEPATH) #get list of questions (by question_id) q = "SELECT question_id FROM quizlink WHERE quiz_id = '%i'" % quiz_id questionlist = __SERVICES__.db.query(q) #get actual questions questions = [] for questionid in questionlist: q = "SELECT * from questions WHERE id = '%i'" % questionid[0] res = __SERVICES__.db.query(q) question = Question() question.id = res[0][0] question.prompt = res[0][1] question.response = res[0][2] question.imgfn = res[0][3] question.sndfn = res[0][4] question.map = res[0][5] question.answer_link = res[0][6] questions.append(question) #copy images and sounds to BUNDLEPATH for question in questions: if len(question.imgfn) > 0: src = IMAGEPATH / question.imgfn path.copy(src, BUNDLEPATH) if len(question.sndfn) > 0: src = SOUNDPATH / question.sndfn path.copy(src, BUNDLEPATH) questions_to_xml(questions, quizname, BUNDLEPATH) fn = quizname + '.iqxo' pth = BUNDLEPATH / fn print 'makebundle: zip_folder', pth zip_folder(BUNDLEPATH, pth) print 'makebundle: write bundle to datastore' dsobject = datastore.create() dsobject.metadata['title'] = quizname dsobject.metadata['mime_type'] = 'application/x-imagequiz' dsobject.set_file_path(pth) datastore.write(dsobject) sf.clear_text_items()
def ask_quiz(cat_id): print 'ask_quiz', cat_id #get list of questions (by question_id) q = "SELECT question_id FROM quizlink WHERE quiz_id = %i" % cat_id questionlist = __SERVICES__.db.query(q) #get actual questions questions = [] for questionid in questionlist: q = 'SELECT * from questions WHERE id = %i' % questionid[0] res = __SERVICES__.db.query(q) question = Question() question.id = res[0][0] question.prompt = res[0][1] question.response = res[0][2] question.imgfn = res[0][3] question.sndfn = res[0][4] question.map = res[0][5] question.answer_link = res[0][6] questions.append(question) questionview(questions, cat_id)
def load_incidents(self): incident_rows = self.database.get_incidents() for incident_row in incident_rows: author = self.get_user(incident_row[1]) status = self.get_stage(incident_row[6]) system = self.get_system_class(incident_row[7]) impact = self.get_impact(incident_row[8]) severity = self.get_severity(incident_row[9]) priority = self.get_priority(incident_row[10]) sla_identification_deadline = TimeUtil.sqlite_to_datetime( incident_row[4]) sla_implementation_deadline = TimeUtil.sqlite_to_datetime( incident_row[5]) incident = Incident(self, incident_row[2], incident_row[3], author, \ sla_identification_deadline, sla_implementation_deadline, status, system, \ impact, priority, severity) incident.id = incident_row[0] incident.date_created = TimeUtil.sqlite_to_datetime( incident_row[11]) incident.date_identified = incident_row[12] incident.date_implemented = incident_row[13] note_rows = self.database.get_notes(incident) for note_row in note_rows: note_id = note_row[0] note_title = note_row[1] note_author = self.get_user(note_row[2]) date_created = note_row[3] note_content = note_row[4] note = Note(note_title, note_author, note_content) note.id = note_id note.date_created = date_created incident.notes.append(note) self.notes[note.id] = note question_rows = self.database.get_questions(incident) for question_row in question_rows: question_id = question_row[0] question_title = question_row[1] question_issuer = self.get_user(question_row[2]) date_asked = question_row[3] question_content = question_row[4] question = Question(question_title, question_issuer, question_content) question.id = question_id question.date_asked = date_asked answer_rows = self.database.get_answers(question) for answer_row in answer_rows: answer_id = answer_row[0] answer_answerer = self.get_user(answer_row[1]) answer_content = answer_row[2] date_answered = answer_row[3] answer = Answer(question, answer_answerer, answer_content) answer.id = answer_id answer.date_answered = date_answered question.answers.append(answer) incident.questions.append(question) self.questions[question.id] = question task_rows = self.database.get_tasks(incident) for task_row in task_rows: task_id = task_row[0] task_name = task_row[1] task_author = self.get_user(task_row[2]) date_created = task_row[3] task_content = task_row[4] task_status = task_row[5] task = Task(task_name, task_author, task_content, task_status) task.id = task_id task.date_created = date_created task_team_rows = self.database.get_task_team_assignment_requests( task) for task_team_row in task_team_rows: task_team = self.get_team(task_team_row[0]) assigner = self.get_user(task_team_row[1]) status = task_team_row[2] date_issued = task_team_row[3] assigned_team = AssignedTeam(task_team, task) assigned_team.status = status assigned_team.date_issued = date_issued task.teams.append(assigned_team) incident.tasks.append(task) self.tasks[task.id] = task self.incidents[incident.id] = incident