Example #1
0
def upload_students():
    print('Adding Students ...')
    with app.app_context():
        for student in students:
            name = student[0]
            email = student[1]
            password = student[2]
            to_add_student = User(name=name, email=email, role='student')
            to_add_student.set_hash(password)
            to_add_student.insert()
            print('[x] Added', student)
Example #2
0
def upload_teachers():
    print('Adding Teachers ...')
    with app.app_context():
        for teacher in teachers:
            name = teacher[0]
            email = teacher[1]
            password = teacher[2]
            to_add_teacher = User(name=name, email=email, role='teacher')
            to_add_teacher.set_hash(password)
            to_add_teacher.insert()
            print('[x] Added', teacher)
Example #3
0
def add_check():
    if request.method == 'POST':
        context = base_context()
        form = AddTeacherForm()
        # if form.validate_on_submit():
        if not form.validate_on_submit():
            flash_errors(form)
            return redirect(url_for('teacher.index'))
        user = User.query.filter(User.email == form.email.data).first()
        if user:
            flash(notify_danger('Mail already exists!'))
            return redirect(url_for('teacher.index'))
        teacher = User(name=form.name.data,
                       email=form.email.data,
                       role='teacher')
        teacher.set_hash(current_app.config['DEFAULT_PASS_ALL'])
        teacher.insert()
        flash(notify_success('Added {}!'.format(teacher.name)))
        return redirect(url_for('teacher.index'))
Example #4
0
def add_check(grade_id):
    if request.method == 'POST':
        context = base_context()
        form = AddStudentForm()
        # if form.validate_on_submit():
        if not form.validate_on_submit():
            flash_errors(form)
            return redirect(url_for('student.view', grade_id=grade_id))

        user = User.query.filter(User.email == form.email.data).first()
        if user:
            flash(notify_danger('Mail already exists!'))
            return redirect(url_for('student.index'))
        student = User(name=form.name.data,
                       email=form.email.data,
                       role='student')
        grade = Grade.query.get(grade_id)
        student.grade = grade
        student.set_hash(current_app.config['DEFAULT_PASS_ALL'])
        student.insert()
        flash(notify_success('Added {}!'.format(form.email.data)))
        return redirect(url_for('student.view', grade_id=grade_id))
Example #5
0
def add_admin(name, email, password):
    with app.app_context():
        admin = User(name=name, email=email, role='admin')
        admin.set_hash(password)
        admin.insert()
        print('[x] added admin:', name, email, password)