def indexC(): session = getSession() connection = session.connection() results = connection.execute( text(''' SELECT competences.id, competences.date, tracks.name as track, categories.NAME AS category, tracks.size AS track_size FROM public.competences INNER JOIN user_competences ON public.competences.id = public.user_competences.competences_id INNER JOIN categories ON competences.category_id = categories.id INNER JOIN tracks ON competences.track_id = tracks.id WHERE user_competences.user_id = :user_id;'''), ({ "user_id": current_user.id })) competences = query_to_dict(results) print(competences) competences = session.query( Competence, Track, Category, UserCompetence).join( UserCompetence, Track, Category).filter(UserCompetence.user_id == current_user.id).all() print(competences) return render_template('competence-table.html', competences=competences)
def api_questionnaires(student_id): allowed_user = int(student_id) authorized, message = auth.authorize_student(allowed_user) if not authorized: return jsonify(message), 401 experiments = models.get_pending_experiments(student_id) exp_dict = utils.query_to_dict(experiments, 'experiments', [(0, 'id'), (1, 'date')]) return jsonify(exp_dict)
def api_list_categories(teacher_id): allowed_user = int(teacher_id) authorized, message = auth.authorize_teacher(allowed_user) if not authorized: return jsonify(message), 401 categories = models.all_categories(teacher_id) cat_dict = utils.query_to_dict(categories, "categories", [(0, "id"), (1, "name")]) return jsonify(cat_dict)
def api_classes(teacher_id): allowed_user = int(teacher_id) authorized, message = auth.authorize_teacher(allowed_user) if not authorized: return jsonify(message), 401 classes = models.get_classes(teacher_id) classes_dict = utils.query_to_dict(classes, 'classes', [(0, 'id'), (1, 'name'), (3, 'description')]) return jsonify(classes_dict), 201
def api_list_experiments(class_id): class_owner = models.run_simple_query( "SELECT teacher_id FROM classes WHERE id = ?", (class_id, ))[0][0] allowed_user = int(class_owner) authorized, message = auth.authorize_teacher(allowed_user) if not authorized: return jsonify(message), 401 experiments = models.list_experiments(class_id) # print(experiments) experiments_dict = utils.query_to_dict(experiments, "experiments", [(0, 'id'), (1, 'date_created')]) return jsonify(experiments_dict)
def api_students(class_id): class_owner = models.run_simple_query( "SELECT teacher_id FROM classes WHERE id = ?", (class_id, ))[0][0] allowed_user = int(class_owner) authorized, message = auth.authorize_teacher(allowed_user) if not authorized: return jsonify(message), 401 students = models.get_students_in_class(class_id) students_dict = utils.query_to_dict(students, 'students', [(0, 'id'), (1, 'name')]) return jsonify(students_dict)
def graph_api(experiment_id): # Authentication class_owner = models.run_simple_query( "SELECT c.teacher_id FROM classes c " "JOIN experiments e on c.id = e.class_id WHERE e.id = ?", (experiment_id, ))[0][0] allowed_user = int(class_owner) authorized, message = auth.authorize_teacher(allowed_user) if not authorized: return jsonify(message), 401 # Get the question text questions = models.get_experiment_details(experiment_id) questions = json.loads(questions) # Get the class id and teacher's name teacher_query = """SELECT c.id, t.name FROM experiments e JOIN classes c on e.class_id = c.id JOIN teachers t on c.teacher_id = t.id WHERE e.id = ?""" class_id, teacher_name = models.run_simple_query(teacher_query, (experiment_id, ))[0] # Get the raw replies replies = models.get_experiment_replies(experiment_id) replies = json.loads(replies) # Get the list of students for nodes students = models.get_students_in_class(class_id) students = utils.query_to_dict(students, 'nodes', [(0, 'id'), (1, 'label'), (0, 'group')]) # for student in students: # student['shape'] = 'circularImage' # student['image'] = '' response = { 'teacher': teacher_name, 'questions': [], 'nodes': students['nodes'] } for i, question in enumerate(questions['questions']): question_dict = { 'text': question['text'], 'type': question['type'], 'edges': [] } # print(question_dict) response['questions'].append(question_dict) # Bit of spaghetti, but builds the edges array for reply_dict in replies['replies']: question_reply = reply_dict['response'][i] if isinstance(question_reply, list): for reply in question_reply: question_dict['edges'].append({ 'from': reply_dict['id'], 'to': reply }) return jsonify(response)