def section4(tree, titles): items = [] song = models.ProgramItem(tree[3][0]['title'], tree[3][0]['duration']) song.time = tree[3][0]['time'] set_song_subtitle(song) items.append(song) for index, item in enumerate(tree[3][1:-2]): index = models.Assignment(item['title'], item['duration'], item['assignee']) index.time = item['time'] items.append(index) comments = models.ProgramItem(tree[3][-2]['title'], 3) comments.time = tree[3][-2]['time'] items.append(comments) prayer = models.Assignment(tree[3][-1]['title'], 5, tree[3][-1]['assignee']) prayer.time = tree[3][-1]['time'] set_song_subtitle(prayer) items.append(prayer) section = models.Section(titles[3], items) return section
def new_grades(): if request.method == 'POST' and request.headers['secret_key'] == session[ 'secret_key']: print(request.json) new_assignment = models.Assignment(assignment_name=request.json['name'], assignment_type=request.json['category'], \ assignment_date=request.json['date'], total_points=request.json['points'], class_id=request.json['id']) db.session.add(new_assignment) print(request.json['student_points']) for (student_id, points) in request.json['student_points'].items(): if points is not None: result = models.AssignmentResult.query.filter_by( assignment_id=new_assignment.id, student_id=student_id).all() if result: result[0].student_id = student_id result[0].points_earned = points else: new_result = models.AssignmentResult( student_id=student_id, assignment_id=new_assignment.id, points_earned=points) db.session.add(new_result) db.session.commit() db.session.close() #get assignment id for adding it to list new_id = models.Assignment.query.filter_by( assignment_name=request.json['name']).first_or_404().id print(new_id) return jsonify(saved=True, id=new_id) else: return jsonify(saved=False)
def section2_part1(section): part1 = section.find(id='p6') treasures = part1.get_text() treasures_duration = 10 item = models.Assignment(treasures, treasures_duration) return item
def create_assignment(intern_id: int, assignment: schemas.AssignmentCreate, db: Session): param = assignment.dict() param.update({'owner_id': intern_id}) db_assignment = models.Assignment(**param) db.add(db_assignment) db.commit() db.refresh(db_assignment) return db_assignment
def section2_part2(section): part2 = section.find(id='p7') gems = part2.get_text() gems_duration = 10 item = models.Assignment(gems, gems_duration) return item
def section1_part1(section): song = section.find(id='p3') opening_song = song.get_text() song_duration = 5 item = models.Assignment(opening_song, song_duration) return item
def section4_parts(section): list_items = section.findAll('li') items = [] song = list_items[0] items.append(models.ProgramItem(song.get_text(), 3)) for item in list_items[1:-2]: text, duration = extract_name_and_duration(item) items.append(models.Assignment(text, duration)) end_comments = list_items[-2] items.append(models.ProgramItem(end_comments.get_text(), 3)) end_song = list_items[-1] items.append(models.Assignment(end_song.get_text(), 5)) return items
def create_assignments(): if not request.is_json: return error.error_400("Expected JSON") try: roomId = request.json["roomId"] except KeyError: return error.error_400("Missing field in body: 'roomId'") try: createdUser = request.json["createdUser"] except KeyError: return error.error_400("Missing field in body: 'createdUser'") try: assignments = request.json["assignments"] except KeyError: return error.error_400("Missing field in body: 'assignments'") created_assignments = list() for assignment in assignments: try: assignedUser = assignment["assignedUser"] except KeyError: return error.error_400( "Missing field in assignment body: 'assignedUser'") try: assignmentName = assignment["name"] except KeyError: return error.error_400("Missing field in assignment body: 'name'") try: assignmentDate = assignment["date"] except KeyError: return error.error_400("Missing field in assignment body: 'date'") newAssignment = models.Assignment(roomid=roomId, createduser=createdUser, assigneduser=assignedUser, assignmentname=assignmentName, date=assignmentDate, completed=False) created_assignments.append(newAssignment) session.add(newAssignment) if len(created_assignments) == 0: return error.error_400("No assignments created") session.commit() return success.success_200({ "createdAssignments": list(map(models.Assignment.get_id, created_assignments)) })
def section2(tree, titles): item0 = tree[1][0] treasures = models.Assignment(item0['title'], item0['duration'], item0['assignee']) treasures.time = item0['time'] item1 = tree[1][1] gems = models.Assignment(item1['title'], item1['duration'], item1['assignee']) gems.time = item1['time'] item2 = tree[1][2] reading = models.StudentsAssignment(item2['title'], item2['duration'], item2['student'], None, item2['point']) reading.time = item2['time'] items = [treasures, gems, reading] sections = models.Section(titles[1], items) return sections
def section3_items(section): list_items = section.findAll('li') L = [] if len(list_items) == 1: title, duration = extract_name_and_duration(list_items[0]) return [models.Assignment(title, duration)] for item in list_items: title, duration = extract_name_and_duration(item) L.append(models.StudentsAssignment(title, duration + 1)) return L
def editAssignmentView(data=None): error = None print(request.method) if data: assignment = models.Assignment.query.filter_by( assignment_id=data).first() questions = models.QuestionTemplate.query.filter_by( assignment_id=data).all() return render_template('editAssignment.html', assignment=assignment, questions=questions) if (request.method == 'POST'): numOfQuestions = len(request.form) - 2 data = request.form.to_dict(flat=False) print(data) assignmentID = int(data['assignmentID'][0]) splitDate = [int(x) for x in data['startDate'][0].split('-')] startDate = date(splitDate[0], splitDate[1], splitDate[2]) splitDate = [int(x) for x in data['endDate'][0].split('-')] endDate = date(splitDate[0], splitDate[1], splitDate[2]) assignment = models.Assignment(id=assignmentID, start_date=startDate, end_date=endDate) db.session.merge(assignment) questions_in_assgn = models.QuestionTemplate.query.filter_by( assignment_id=assignmentID).all() for key, value in data.items(): if not key in ['assignmentID', 'startDate', 'endDate']: question = models.QuestionTemplate.query.filter_by( id=int(key)).first() if question: questions_in_assgn.remove(question) question.question_text = value[0] db.session.merge(question) else: for i, body in enumerate(value): try: question = models.QuestionTemplate( id=models.QuestionTemplate.query.count() + i, question_text=body, solution_formula='temp', error_margin=0, assignment_id=assignmentID) db.session.add(question) except Exception as e: print(e) print('Couldnt put this question into database') db.session.commit() deleteQuestionFromDB(questions_in_assgn) return redirect(url_for('index'))
def section1(tree, titles): item0 = tree[0][0] song = models.Assignment(item0['title'], 5, item0['assignee']) song.time = item0['time'] set_song_subtitle(song) item1 = tree[0][1] comments = models.ProgramItem(item1['title'], 3) comments.time = item1['time'] items = [song, comments] section = models.Section(titles[0], items) return section
def section3(tree, titles): items = [] for index, item in enumerate(tree[2]): if 'student' in item: index = models.StudentsAssignment( item['title'], item['duration'], item['student'], item['partner'], *get_point_title_and_url(item['point'])) index.time = item['time'] items.append(index) else: index = models.Assignment(item['title'], item['duration'], item['assignee']) index.time = item['time'] items.append(index) section = models.Section(titles[2], items) return section
def createAssignmentView(): error = None if (request.method == 'POST'): data = request.form.to_dict(flat=False) numOfQuestions = int(data['numQuestions'][0]) if (len(data['assignmentID'][0]) > 0 and len(data['startDate'][0]) > 0 and len(data['endDate'][0]) > 0): assignmentID = int(data['assignmentID'][0]) splitDate = [int(x) for x in data['startDate'][0].split('/')] startDate = date(splitDate[2], splitDate[0], splitDate[1]) splitDate = [int(x) for x in data['endDate'][0].split('/')] endDate = date(splitDate[2], splitDate[0], splitDate[1]) assignment = models.Assignment(id=assignmentID, start_date=startDate, end_date=endDate) else: error = 'Fill in all sections' if not error: i = 1 questions = [] while (i <= numOfQuestions): try: qtype = data['questionType{}'.format(i)][0] if qtype == "True or False": question = models.TrueFalse( id=models.QuestionTemplate.query.count() + i - 1, question_text=data['question{}'.format(i)][0], type=data['questionType{}'.format(i)][0], assignment_id=assignmentID) question.answer = (True if ((data['answerTF{}'.format(i)][0]) == 'True') else False) questions.append(question) elif qtype == "Short Answer": question = models.ShortAnswer( id=models.QuestionTemplate.query.count() + i - 1, question_text=data['question{}'.format(i)][0], type=data['questionType{}'.format(i)][0], assignment_id=assignmentID) question.error_margin = int( data['errorMargin{}'.format(i)][0]) questions.append(question) elif qtype == "Multiple Choice": question = models.MultipleChoice( id=models.QuestionTemplate.query.count() + i - 1, question_text=data['question{}'.format(i)][0], type=data['questionType{}'.format(i)][0], assignment_id=assignmentID) question.multipleChoice1 = data['radioText{}'.format( i)][0] question.multipleChoice2 = data['radioText{}'.format( i)][1] question.multipleChoice3 = data['radioText{}'.format( i)][2] question.multipleChoice4 = data['radioText{}'.format( i)][3] question.multipleChoice5 = data['radioText{}'.format( i)][4] question.correct = int( data['radio{}'.format(i)][0][-1]) questions.append(question) except Exception as e: print(e) print('Couldnt put this questions into database') i += 1 grades = [] for student in models.Student.query.all(): try: grade = models.StudentGrade(student_id=student.student_id, assignment_id=assignmentID) grades.append(grade) except Exception as e: print(e) print('Couldnt put grade into database') db.session.add_all([assignment] + questions + grades) db.session.commit() return redirect(url_for('index')) return render_template('createAssignment.html', error=error)