def admin_edit_questions(): questions = [] answers = [] files = [] ansData = {} data = {} counter = 1 ansNum = 1 fileCounter = 1 # Build Dictionary for questions pulled from the db for question in database_session.query(Questions.question, Questions.section).distinct(): data['id'] = counter currentQuestion = question.question data['question'] = currentQuestion section = question.section data['section'] = section for answer in database_session.query( Questions.answer, Questions.is_correct).filter( Questions.question == question.question): ansData = {} if answer.is_correct: ansData['is_correct'] = True else: ansData['is_correct'] = False ansData['ansCounter'] = counter ansData['ans_id'] = ansNum ansData['answer'] = answer.answer ansData['is_correct'] = answer.is_correct answers.append(ansData) ansNum += 1 for file in database_session.query(QuestionsImages.file_name).filter( QuestionsImages.question == question.question): fileData = {} fileData['file_id'] = fileCounter fileData['file_counter'] = counter file_name = file.file_name fileData['file'] = file_name files.append(fileData) fileCounter += 1 questions.append(data) ansNum = 1 counter += 1 data = {} response = make_response( render_template('questionEditUI.html', questions=questions, answers=answers, files=files, home_link='./')) response.headers[ "Cache-Control"] = "no-cache, no-store, must-revalidate" # HTTP 1.1. response.headers["Pragma"] = "no-cache" # HTTP 1.0. response.headers["Expires"] = "0" # Proxies. return response
def grader_index(): teamsData = [] testNames = [] for team in database_session.query(StudentTeam): teamData = { "team_name": team.team_name, "team_year": team.team_year, "test_name": "?", "sec_one_score": "?", "sec_two_score": "?", "sec_three_score": "?", "total_score": "?" } student_scores = StudentScore.query.filter_by( team_name=team.team_name).order_by(StudentScore.team_year).first() if student_scores: teamData["test_name"] = student_scores.test_name teamData["sec_one_score"] = student_scores.section_one_score teamData["sec_two_score"] = student_scores.section_two_score teamData["sec_three_score"] = student_scores.section_three_score teamData["total_score"] = student_scores.total_score if student_scores.test_name not in testNames: testNames.append(student_scores.test_name) teamsData.append(teamData) return render_template('grader_home.html', teamsData=teamsData, testNames=testNames)
def student_s3(): student_team = StudentTeam.query.filter_by(team_name=current_user.username).order_by(StudentTeam.team_year).first() exam_questions_s3 = [] images=[] question = {} fileData = {} counter = 0 fileCounter = 0 # Build Dictionary for questions pulled from the db # TODO grab the correct exam for this team! for counter, exam_question_s3 in enumerate(database_session.query(iComputeTest.question).filter(and_(iComputeTest.test_name == student_team.test_id, iComputeTest.section == 3)).order_by(iComputeTest.orderId), start=1): question['id'] = counter question['question'] = exam_question_s3.question for data in database_session.query(QuestionsImages.data).filter(QuestionsImages.question == exam_question_s3.question): fileData = {} fileData['file_id'] = fileCounter fileData['file_counter'] = counter image = base64.encodestring(data.data) image2 = image.decode("UTF8") fileData['image'] = image2 images.append(fileData) fileCounter +=1 exam_questions_s3.append(question) counter += 1 question = {} if request.method == 'POST': if ('inputFile' in request.files) and ('hiddenfield_id' in request.form): file = request.files['inputFile'] myQuestion = request.form['hiddenfield_id'] database_session.add(StudentAnswer( team_name=current_user.username, team_year=student_team.team_year, section=3, # TODO since the question was escaped we may need to unescape it here question=myQuestion, answer=file.filename, scratch_file=file.read())) database_session.commit() current_user.password = '******' database_session.commit() logout_user() flash('Your answers have been submitted. Thank you for participating!', 'info') return redirect(url_for('index')) return render_template('scratch_submit.html', exam_questions_s3 = exam_questions_s3, images = images)
def delete_answer(): if 'question' in request.form and 'answer' in request.form: del_query = database_session.query(Questions.answer).filter( and_(Questions.question == request.form['question'], Questions.answer == request.form['answer'])) del_query.delete() database_session.commit() return "success"
def delete_question(): if 'question' in request.form: del_query = database_session.query(Questions).filter( Questions.question == request.form['question']) del_query.delete() database_session.commit() del_query = database_session.query(iComputeTest).filter( iComputeTest.question == request.form['question']) del_query.delete() database_session.commit() del_query = database_session.query(QuestionsImages).filter( QuestionsImages.question == request.form['question']) del_query.delete() database_session.commit() return "success"
def delete_image(): if 'question' in request.form and 'file_name' in request.form: del_query = database_session.query(QuestionsImages.file_name).filter( and_(QuestionsImages.question == request.form['question'], QuestionsImages.file_name == request.form['file_name'])) del_query.delete() database_session.commit() return "success"
def admin_test(): questions = [] question = {} testNames = [] for counter, exam_question in enumerate(database_session.query( Questions.question, Questions.section).distinct(), start=1): question['id'] = str(counter) question['question'] = exam_question.question question['answers'] = [] question['side'] = "left" question['section'] = exam_question.section for answer in database_session.query( Questions.answer, Questions.is_correct).filter( Questions.question == exam_question.question): question['answers'].append({ "answer": escape(answer.answer), "is_correct": escape(answer.is_correct) }) questions.append(question) question = {} for test in database_session.query(iComputeTest.test_name).distinct(): testNames.append(test.test_name) if request.method == "POST": test_name = request.form['test'] for exam_question in database_session.query( iComputeTest.question).filter( iComputeTest.test_name == test_name): for question in questions: if question['question'] == exam_question.question: question['side'] = "right" return render_template('test.html', questions=questions, tests=testNames, link=url_for('admin.admin_index'), active_select=test_name) return render_template('test.html', questions=questions, tests=testNames, link=url_for('admin.admin_index'), active_select='New Test')
def edit_answer(): if 'question' in request.form and 'answer' in request.form and 'new_answer' in request.form: rows_to_update = database_session.query(Questions).filter( Questions.question == request.form['question'], Questions.answer == request.form['answer']) for row in rows_to_update: row.answer = request.form['new_answer'] database_session.commit() return redirect(url_for('admin.admin_edit_questions'))
def edit_question(): if 'question' in request.form and 'new_question' in request.form: rows_to_update = database_session.query(Questions).filter( Questions.question == request.form['question']) test_rows_to_update = database_session.query(iComputeTest).filter( iComputeTest.question == request.form['question']) for row in rows_to_update: row.question = request.form['new_question'] for row in test_rows_to_update: row.question = request.form['new_question'] database_session.commit() rows_to_update = database_session.query(QuestionsImages).filter( QuestionsImages.question == request.form['question']) for row in rows_to_update: row.question = request.form['new_question'] database_session.commit() return "success"
def test_remove_question(): if ('testId' in request.form) and ('question' in request.form): question = database_session.query(iComputeTest).filter_by( test_name=request.form['testId'], question=request.form['question']).first() if question: database_session.delete(question) database_session.commit() return 'success' return 'error'
def student_team_index(): student_team = StudentTeam.query.filter_by(team_name=current_user.username).order_by(StudentTeam.team_year).first() exam_questions_s1 = [] question = {} # Build Dictionary for questions pulled from the db # TODO grab the correct exam for this team! for counter, exam_question_s1 in enumerate(database_session.query(iComputeTest.question).filter(and_(iComputeTest.test_name == student_team.test_id, iComputeTest.section == 1)).order_by(iComputeTest.orderId), start=1): question['id'] = str(counter) question['question'] = exam_question_s1.question question['answers'] = [] for answer in database_session.query(Questions.answer).filter(Questions.question == exam_question_s1.question): question['answers'].append(escape(answer.answer)) random.shuffle(question['answers']) exam_questions_s1.append(question) question = {} # Grab the Student submitted answers off the form and submit to database if request.method == 'POST': for question in exam_questions_s1: form_response = request.form[question['id']] if question['id'] in request.form else None database_session.add(StudentAnswer( team_name=current_user.username, team_year=student_team.team_year, section=1, # TODO since the question was escaped we may need to unescape it here question=question['question'], answer=form_response)) database_session.commit() grade_section_one(current_user.username) # For now when the team is done taking the test the application will destroy the password and log the team out. return redirect(url_for('student_team.student_s3')) return render_template('multiple_choice.html', exam_questions_s1 = exam_questions_s1)
def edit_question(): if 'team_name' in request.form and 'team_year' in request.form and 'section' in request.form and 'score' in request.form: if request.form['section'] == 'section_three': rows_to_update = database_session.query(StudentScore).filter( StudentScore.team_name == request.form['team_name'], StudentScore.team_year == request.form['team_year']) for row in rows_to_update: row.section_three_score = request.form['score'] row.total_score = ( row.section_one_score + (row.section_two_score if row.section_two_score else 0) + int(row.section_three_score)) database_session.commit() return "success"
def grade_section_one(team): student_team = StudentTeam.query.filter_by(team_name=team).order_by(StudentTeam.team_year).first() total_questions = database_session.query(iComputeTest).filter(iComputeTest.test_name==student_team.test_id).count() correct_answers = 0 for response in StudentAnswer.query.filter_by(team_name=team).all(): question = Questions.query.filter_by(question=response.question, is_correct=True).first() if question: if response.answer == question.answer: correct_answers += 1 student_score = StudentScore(team_name=student_team.team_name, team_year=student_team.team_year, test_name=student_team.test_id, total_score=(correct_answers*2), # WESO Scoring says that each multiple choice question is worth 2 points section_one_score=(correct_answers*2), section_two_score=0, section_three_score=0) database_session.add(student_score) database_session.commit()
def admin_edit_users(): supervisorArray = [] data = {} counterSupervisor = 1 # Build Dictionary users for supervisor in database_session.query(Users).filter( Users.user_type == 'Supervisor'): data['id'] = counterSupervisor currentSupervisor = supervisor.username data['supervisor'] = currentSupervisor supervisorArray.append(data) counterSupervisor += 1 data = {} graderArray = [] data = {} counterGrader = 1 # Build Dictionary users for grader in database_session.query(Users).filter( Users.user_type == 'Grader'): data['id'] = counterGrader currentGrader = grader.username data['grader'] = currentGrader graderArray.append(data) counterGrader += 1 data = {} studentTeamArray = [] data = {} counterStudent = 1 # Build Dictionary users for studentTeam in database_session.query(Users).filter( Users.user_type == 'Student'): data['id'] = counterStudent currentStudentTeam = studentTeam.username data['studentTeam'] = currentStudentTeam print(currentStudentTeam) studentTeamArray.append(data) counterStudent += 1 data = {} tests = [] data = {} counterTests = 1 for test in database_session.query(iComputeTest.test_name).distinct(): data['id'] = counterTests data['test_name'] = test.test_name tests.append(data) counterTests += 1 data = {} return render_template('userAdd.html', supervisorArray=supervisorArray, graderArray=graderArray, studentTeamArray=studentTeamArray, tests=tests)
def admin_view_results(): exam_results = [] exam_data = {} # Build Dictionary for test names pulled from the db for counter, test_name in enumerate(database_session.query( StudentScore.test_name).distinct().order_by( StudentScore.test_name), start=1): exam_data['id'] = counter exam_data['test_name'] = test_name.test_name # Set up for different cards on the accordian html section exam_data['accord1'] = "#collapse" + str(counter) exam_data['accord2'] = "collapse" + str(counter) # Set up for the rest of the data needed exam_data['student_teams'] = [] exam_results.append(exam_data) exam_data = {} # Add the rest of the data in a sub Dictionary of each test details = {} for exam_result in exam_results: # for each test, grab all team results of that test for test_result in database_session.query(StudentScore).filter( StudentScore.test_name == exam_result['test_name']).order_by( StudentScore.total_score.desc()): details['team_name'] = test_result.team_name for team_info in database_session.query(StudentTeam).filter( StudentTeam.team_name == details['team_name']): details['school_name'] = team_info.school_name details['team_year'] = test_result.team_year details['sectionAScore'] = test_result.section_one_score details['sectionBScore'] = test_result.section_two_score details['sectionCScore'] = test_result.section_three_score details['totalScore'] = test_result.total_score exam_result['student_teams'].append(details) details = {} if request.method == 'POST': theName = request.form["testForm"] full_info = [] for exam_result in exam_results: if (exam_result['test_name'] == theName): full_info = full_info + list(exam_result['student_teams']) full_csv = render_template('full_scores.csv', all_scores=full_info) response = make_response(full_csv) response.headers['Cache-Control'] = 'must-revalidate' response.headers['Pragma'] = 'must-revalidate' response.headers['Content-type'] = 'text/csv' response.headers[ 'Content-Disposition'] = f'attachment; filename=' + theName + '.csv' return response return render_template('testResults.html', link="./", exam_results=exam_results, home_link='./')
def clear_student_answers(): del_query = database_session.query(StudentAnswers) del_query.delete() database_session.commit()
def admin_view_test(): test_names = [] for test in database_session.query(iComputeTest.test_name).distinct(): test_names.append(test.test_name) if request.method == "POST": exam_questions_s1 = [] question = {} for counter, exam_question_s1 in enumerate(database_session.query( iComputeTest.question).filter( iComputeTest.test_name == request.form['test']).order_by( iComputeTest.orderId), start=1): question['id'] = str(counter) question['question'] = exam_question_s1.question question['answers'] = [] for answer in database_session.query(Questions.answer).filter( Questions.question == exam_question_s1.question): question['answers'].append(escape(answer.answer)) for section in database_session.query(Questions.section).filter( Questions.question == exam_question_s1.question): question['section'] = section.section exam_questions_s1.append(question) question = {} test = database_session.query(iComputeTest).filter( iComputeTest.test_name == request.form['test']).first() exam_questions_s3 = [] images = [] question = {} fileData = {} counter = 0 fileCounter = 0 # Build Dictionary for questions pulled from the db # TODO grab the correct exam for this team! for counter, exam_question_s3 in enumerate(database_session.query( iComputeTest.question).filter( and_(iComputeTest.test_name == request.form['test'], iComputeTest.section == 3)).order_by( iComputeTest.orderId), start=1): question['id'] = counter question['question'] = exam_question_s3.question for data in database_session.query(QuestionsImages.data).filter( QuestionsImages.question == exam_question_s3.question): fileData = {} fileData['file_id'] = fileCounter fileData['file_counter'] = counter image = base64.encodestring(data.data) image2 = image.decode("UTF8") fileData['image'] = image2 images.append(fileData) fileCounter += 1 exam_questions_s3.append(question) counter += 1 question = {} return render_template('test_view.html', name=test.test_name, year=test.year, grade=test.student_grade, is_chosen=True, tests=test_names, exam_questions_s1=exam_questions_s1, exam_questions_s3=exam_questions_s3, images=images) return render_template('test_view.html', is_chosen=False, tests=test_names)