Example #1
0
def addStudent():
    from forms import StudentForm
    form = StudentForm(request.form)
    if request.method == "POST" and form.validate():
        s = Student(name=form.name.data, course=form.course.data)
        db.session.add(s)
        db.session.commit()
    return render_template('addstudent.html', form=form)
Example #2
0
def index():
    if request.method == 'POST':
        form = StudentForm(request.form)
        if form.validate():
            new_student = Student(request.form['first_name'],
                                  request.form['last_name'])
            db.session.add(new_student)
            db.session.commit()
            return redirect(url_for('index'))
        return render_template('students/new.html', form=form)
    return render_template('students/index.html', students=Student.query.all())
def new_student():
    #Add a new student
    form = StudentForm(request.form)

    if request.method == 'POST' and form.validate():
        # save the album
        student = Student()
        save_changes(student, form, new=True)
        flash('Student successfully added to database!')
        return redirect('/')

    return render_template('new_student.html', form=form)
Example #4
0
def add_edit_student(studentId):
	errorList = []
	form = StudentForm()

	if request.method == 'POST':
		try:
			form = StudentForm(request)
			errorList = form.validate()
			if not errorList:
				student = form.save()
				return redirect(url_for('list_student'))
		except Exception as e:
			traceback.print_exc()
			errorList.append(str(e))
	elif studentId>0:
		student = db_service.getStudentById(studentId)
		form = StudentForm(dbModel=student)
	return render_template('add_edit_student.html', form=form, errorList=errorList)
Example #5
0
def add_student():
    """ View add student form. """
    form = StudentForm(request.form)

    if request.method == 'POST' and form.validate():

        student = Student(form.roll_number.data, form.name.data,
                          form.rank.data)

        try:
            # Try to add student record to database
            db = DBHandler(DBNAME)
            db.add_student(student)
            db.close_connection()
        except sqlite3.IntegrityError as e:
            # Primary key constraint: Roll number already exists
            flash('Roll number already exists.')
            return render_template('add.html', form=form)

        return redirect(url_for('view_all'))

    return render_template('add.html', form=form)
Example #6
0
def student(id):
    if current_user.role_name != 'AdminUser':
        return render_error(403)
    if id == 'new':
        s = Student()
    else:
        try:
            id = int(id)
        except ValueError:
            return render_error(400)
        s = db.session.query(Student).filter(Student.id == id).one_or_none()
        if s is None:
            return render_error(404)

    form = StudentForm(request.form if request.method == 'POST' else None, obj=s)  # WFORMS-Alchemy Объект на форму

    if form.button_delete.data:
        form.validate()
        if db.session.query(AttMark).filter(AttMark.student_id == s.id).count() > 0:
            form.button_delete.errors.append('Невозможно удалить студента, у которого есть оценки за аттестации')

        if len(form.button_delete.errors) == 0:
            db.session.delete(s)
            db.session.commit()
            db.session.flush()
            return redirect(url_for('students'))

    if form.button_save.data and form.validate():
        form.populate_obj(s) #WFORMS-Alchemy с формы на объект
        if s.status == "alumnus":
            s.stud_group = None
            s.expelled_year = None
            s.semester = None
            if s.alumnus_year is None:
                s.alumnus_year = datetime.now().year

        if s.status in ("expelled", "academic_leave"):
            s.stud_group = None
            s.alumnus_year = None
            if s.expelled_year is None:
                s.expelled_year = datetime.now().year

        if s.stud_group is not None:
            s.status = "study"
            s.semester = s.stud_group.semester
        else:
            s.group_leader = False

        if s.status == "study":
            s.alumnus_year = None
            s.expelled_year = None

        form = StudentForm(obj=s)

        if form.validate():
            if s.status != "alumnus" and s.semester is None:
                form.semester.errors.append("Укажите семестр")
            if len(form.semester.errors) == 0:
                db.session.add(s)
                db.session.commit()
                if id == 'new':
                    db.session.flush() # ???
                if s.id != id:
                    return redirect(url_for('student', id=s.id))

    return render_template('student.html', student=s, form=form)