示例#1
0
def add_student():
    """
    Add a student to the database
    """
    check_admin()

    add_student = True

    form = StudentForm()
    if form.validate_on_submit():
        student = Student(name=form.name.data, forum=form.forum.data)
        try:
            # add student to the database
            db.session.add(student)
            db.session.commit()
            flash('You have successfully added a new student.')
        except:
            # in case student name already exists, FIX LATER
            flash('Error: student name already exists.')

        # redirect to students page
        return redirect(url_for('teaching_fellow.list_students'))

    # load student template
    return render_template('teaching_fellow/students/student.html',
                           action="Add",
                           add_student=add_student,
                           form=form,
                           title="Add Student")
示例#2
0
def edit_student(id):
    """
    Edit a student
    """
    check_admin()

    add_student = False

    student = Student.query.get_or_404(id)
    form = StudentForm(obj=student)
    if form.validate_on_submit():
        student.name = form.name.data
        student.forum = form.forum.data
        db.session.commit()
        flash('You have successfully edited the student.')

        # redirect to the students page
        return redirect(url_for('teaching_fellow.list_students'))

    form.name.data = student.name
    form.forum.data = student.forum
    return render_template('teaching_fellow/students/student.html',
                           action="Edit",
                           add_student=add_student,
                           form=form,
                           student=student,
                           title="Edit Student")
示例#3
0
def student():
    form = StudentForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            session['number_of_dates'] = form.number_of_dates.data
            if form.dates:
                dates = []
                images = []
                for date in form.dates:
                    datex = datetime.date(date.year.data,
                                          date.month.data,
                                          date.day.data)
                    dates.append(datex.toordinal())
                    images.append(get_img(datex))
                session["dates"] = dates
                session["images"] = images
                return redirect(url_for('student'))
            return redirect(url_for('student'))
        else:
            return render_template('student.html', form = form)
    elif request.method == 'GET':
        if session.get('number_of_dates'):
            form.add_dates(session.get('number_of_dates'))
        form.number_of_dates.data = session.get('number_of_dates')
        if session.get('dates'):
            dates = [datetime.date.fromordinal(date)
                     for date in session.get('dates')]
        else:
            dates = None
        images = session.get('images')
        if images:
            images = zip(dates, images)
        return render_template('student.html', form = form,
                               images = images)
示例#4
0
def edit_student(id):
    """
    Edit a student
    """
    check_admin()

    add_student = False

    student = Student.query.get_or_404(id)
    form = StudentForm(obj=student)
    if form.validate_on_submit():
        student.student_fname = form.student_fname.data
        student.student_lname = form.student_fname.data
        student.student_number = form.student_number.data
        student.contact_mobile = form.contact_mobile.data
        student.contact_email = form.contact_email.data
        db.session.add(student)
        db.session.commit()
        flash('You have successfully edited the student.')

        # redirect to the students page
        return redirect(url_for('admin.list_students'))

    form.contact_email.data = student.contact_email
    form.contact_mobile.data = student.contact_mobile
    form.student_number.data = student.student_number
    form.student_fname.data = student.student_lname
    form.student_fname.data = student.student_fname
    return render_template('admin/students/student.html',
                           add_student=add_student,
                           form=form,
                           title="Edit Student")
示例#5
0
def add_student():
    """
    Add a student to the database
    """
    check_admin()

    add_student = True

    form = StudentForm()
    if form.validate_on_submit():
        student = Student(student_fname=form.student_fname.data,
                          student_lname=form.student_lname.data,
                          student_number=form.student_number.data,
                          contact_mobile=form.contact_mobile.data,
                          contact_email=form.contact_email.data)

        try:
            # add student to the database
            db.session.add(student)
            db.session.commit()
            flash('You have successfully added a new student.')
        except:
            # in case student name already exists
            flash('Error: student name already exists.')

        # redirect to the students page
        return redirect(url_for('admin.list_students'))

    # load student template
    return render_template('admin/students/student.html',
                           add_student=add_student,
                           form=form,
                           title='Add Student')
def contact():
    form = StudentForm()
    if request.method == 'POST' and form.validate_on_submit():
        print("saved")
        flash('Student Successfully saved!', "success")
        return render_template('index.html', form=form)
    print("not validate")
    return render_template('index.html', form=form)
示例#7
0
def index():
    form = StudentForm()
    if form.validate_on_submit():
        if request.method == 'POST':
            fullName = form.fullName.data
            email = form.email.data
            phoneNumber = form.phoneNumber.data
            students.insert({
                'fullName': fullName,
                'email': email,
                'phoneNumber': phoneNumber
            })
            return redirect(url_for('index', message='Data Added'))

    return render_template('index.html', form=form)
示例#8
0
def addStudent(classId=None):
    if classId is None:
        abort(404)
    klass = Class.query.filter_by(id=classId).first_or_404()
    if klass.user_id != g.user.id:
        #Access Denied
        abort(401)
    form = StudentForm()
    if form.validate_on_submit():
        name = form.name.data
        student = Student(name=name, class_id=classId)
        db.session.add(student)
        db.session.commit()
        flash('add Student success')
        return redirect(url_for('viewClass', classId=classId))
    return render_template('addStudent.html', form=form, klass=klass)
示例#9
0
def student():
    form = StudentForm()
    if form.validate_on_submit():
        Student(current_user.id, form.name.data, form.phone.data,
                form.email.data, form.dob.data, form.branch.data,
                form.minor.data, form.year.data).save()
        commit()
        flash('Data updated successfully', 'success')
        return redirect(url_for('student.student'))
    student_value = Student.load(current_user.id)
    if student_value is not None:
        form.name.data = student_value.name
        form.phone.data = student_value.phone
        form.email.data = student_value.email
        form.dob.data = student_value.dob
        form.branch.data = student_value.branch
        form.minor.data = student_value.minor
        form.year.data = student_value.year
    return render_template('student.html', form=form)
示例#10
0
def edit(_id):
    student = students.find_one({"_id": ObjectId(_id)})
    form = StudentForm()
    if request.method == 'GET':
        form.fullName.data = student['fullName']
        form.email.data = student['email']
        form.phoneNumber.data = student['phoneNumber']
    elif request.method == 'POST':
        if form.validate_on_submit():
            fullName = form.fullName.data
            email = form.email.data
            phoneNumber = form.phoneNumber.data
            students.update({"_id": ObjectId(_id)}, {
                '$set': {
                    "fullName": fullName,
                    "email": email,
                    "phoneNumber": phoneNumber
                }
            })
            return redirect(url_for('view', message='Data Updated'))
    return render_template('edit.html', form=form)
示例#11
0
def add_student():
    """
    Add a student to the database
    """

    add_student = True

    form = StudentForm()

    if form.validate_on_submit():
        student = Student(first_name=form.first_name.data,
                          last_name=form.last_name.data,
                          student_number=form.student_number.data)

        try:
            # add student to the database
            db.session.add(student)
            db.session.commit()
            #create all marks for current student
            for mark in form.student_marks.data:
                student_mark = Mark(mark, student.id)

                # add student marks to the database
                db.session.add(student_mark)
                db.session.commit()

            flash('You have successfully added a new student.')
        except:
            # in case student number already exists
            flash('Error: Student number ' + str(student.student_number) +
                  ' already exists.')

        # redirect to the students page
        return redirect(url_for('home.list_students'))

    # load student template
    return render_template('student.html',
                           add_student=add_student,
                           form=form,
                           title='Add Student')
示例#12
0
def edit_student(id):
    """
    Edit a student
    """
    add_student = False

    student = Student.query.get_or_404(id)
    form = StudentForm(obj=student)
    if form.validate_on_submit():
        student.first_name = form.first_name.data
        student.last_name = form.last_name.data
        student.student_number = form.student_number.data

        # update studentin database
        db.session.merge(student)
        db.session.commit()
        #create all marks for current student
        for mark in form.student_marks.data:
            student_mark = Mark(mark, student.id)
            # update student marks in database
            db.session.merge(student_mark)
            db.session.commit()

        flash('You have successfully updated student and student marks.')

        # redirect to the students page
        return redirect(url_for('home.list_students'))

        #marks=Mark.query.filter_by(Mark.student_id == id).all()
        selected_marks = Mark.query.filter_by(Mark.student_id == id).all()

        form.first_name.data = student.first_name
        form.last_name.data = student.last_name
        form.student_number.data = student.student_number
        form.student_marks.data = selected_marks
    return render_template('student.html',
                           add_student=add_student,
                           form=form,
                           title='Add Student')