def get_checkpoint_username(self): """ Get student name :return: List of objects """ student = Student.get_by_id(self.student_id) if student: return student.username return None
def delete(student_id): """ Remove student from list(data base) :param student_id: int GET return list of students without removed student """ student = Student.get_by_id(student_id) if student: student.delete_student() flash('Student was deleted') return redirect(url_for('student_controller.list_students')) return redirect(url_for('student_controller.list_students'))
def grade_user_assignments(username): """ Grade assignment of user if you are mentor :param username: :return: """ if request.method == "POST": if request.form['grade_user'] == 'grade': assignment_id = request.form['assignment'] student_id = request.form['id'] assignment = Assignment.get_by_id(assignment_id) student = Student.get_by_id(student_id) student_submit = Submition.get_submit(student_id, assignment_id) return render_template('grade_user_assignments.html', user=user_session(session['user'], session['type']), student=student, assignment=assignment, student_submit=student_submit) elif request.form['grade_user'] == 'Save': submit_id = request.form['submit_id'] new_grade = request.form['new_grade'] assignment_id = request.form['assignment_id'] assignment = Assignment.get_by_id(assignment_id) submit = Submition.get_by_id(submit_id) if assignment.type == 'group': team_id = Student.get_by_id(submit.student_id).team_id team = Team.get_by_id(team_id) team_members = team.get_members() for student in team_members: submit = Submition.get_submit(student.id, assignment_id) submit.update_grade(new_grade) else: submit.update_grade(new_grade) return redirect( url_for('assignment_controller.grade_assignment', assignmentID=assignment_id)) return render_template('404.html', user=user_session(session['user'], session['type']))
def user_session(id, class_name): """Return object with given class name in class_name and id""" if class_name == "Student": return Student.get_by_id(id) elif class_name == "Mentor": return Mentor.get_by_id(id) elif class_name == "Employee": return Employee.get_by_id(id, 'assistant') elif class_name == "Manager": return Manager.get_by_id(id) return None
def edit_student(student_id): """ Edit student formula to edit student details :param student_id: int GET return edit student formula POST return list of students with edited student changes saved """ teams = Team.list_teams() student = Student.get_by_id(student_id) print('Editing') if student: if request.method == 'POST': save_student('edit', student.id) flash('Student was edited') return redirect(url_for('student_controller.list_students')) return render_template('edit_student_form.html', user=user_session(session['user'], session['type']), student=student, teams=teams) return redirect('list-students')
def save_student(save, id=None): print('asdasdasd') if save == 'add': student = Student(id=id, first_name=request.form['first-name'], last_name=request.form['last-name'], password=request.form['password'], telephone=request.form.get('phone-number', ''), mail=request.form.get('mail', ''), team_id=request.form.get('team', '')) print('ADD') student.add_student() elif save == 'edit' and id: # SQLALCHEMY - need to get element from db and edit it , rather then create new object (won't work , other way) print('IN EDIT') student = Student.get_by_id(id) student.first_name = request.form['first-name'] student.last_name = request.form['last-name'] student.password = request.form['password'] student.telephone = request.form.get('phone-number', '') student.mail = request.form.get('mail', '') student.team_id = request.form.get('team', '') student.add_student()