def validate_all(pre_post, course_name): """Set the time validity for all students of a course to 1.""" course_db = CourseDB() course_id = course_db.get_course_id(course_name)[0] questionnaire_db = QuestionnaireDB() if pre_post not in ["pre", "post"]: print("Unknown pre_post specifier {}, should be 'pre' or 'post'" "".format(pre_post)) return query = """ UPDATE student_{} SET valid_time = 1 WHERE student_id IN ( SELECT student_id FROM student_course WHERE course_id = ? ) """.format(pre_post) questionnaire_db.execute(query, (course_id, )) questionnaire_db.db.commit()
def test_get_course_id(app): with app.app_context(): identifiers = {'abxce': 1, 'tryui': 2, 'oiuyt': 3, 'ertyu': 4} course_db = CourseDB() for key in identifiers: course_id = course_db.get_course_id(key) assert course_id[0] == identifiers[key]
def insert_data(self, df): """Insert new data into the database.""" course_db = CourseDB() for _, row in df.iterrows(): course_id = course_db.get_course_id(row['course_id']) if course_id is not None: student_id = self._add_student(row['personal_code'], course_id[0]) else: student_id = self._add_student(row['personal_code']) self._add_student_unknown_course(student_id, row['course_id']) if row['pre_post'] == 1: questionnaire_id = self._add_pre_questionnaire(row) self._add_student_prepost(row, student_id, questionnaire_id, 'pre') elif row['pre_post'] == 2: questionnaire_id = self._add_post_questionnaire(row) self._add_student_prepost(row, student_id, questionnaire_id, 'post')