示例#1
0
def create_people():
    form = UserForm()
    try:
        result = db.session.query(People).filter(People.people_name == form.people_name.data).one()
        if result != 0:
            return render_template('create_people.html', people_name="People exist", form=form)
    except:
        pass

    if request.method == 'POST':
        if form.validate() and form.validate_birthday():
            new_people = People(
                people_name=form.people_name.data,
                people_birthday=form.people_birthday.data.strftime("%Y-%m-%d"),
                people_email=form.people_email.data,
                people_phone=form.people_phone.data,
            )
            db.session.add(new_people)
            db.session.commit()
            return redirect('/people')
        else:
            if not form.validate_birthday():
                form.people_birthday.errors = ['should be >1900']
            return render_template('create_people.html', form=form)
    elif request.method == 'GET':
        return render_template('create_people.html', form=form)
示例#2
0
def create_user():
    form = UserForm()

    if request.method == 'POST':
        count = db.session.query(User).filter(
            User.user_email == form.user_email.data).one_or_none()

        if count == None:
            roles = db.session.query(ormRole).filter(
                ormRole.name == "User").one()
            new_user = user_datastore.create_user(
                username=form.user_name.data,
                password=form.password.data,
                email=form.user_email.data,
                user_email=form.user_email.data,
                user_name=form.user_name.data,
                user_phone=form.user_phone.data,
                user_birthday=form.user_birthday.data.strftime("%Y-%m-%d"))
            new_user.roles.append(roles)
            db.session.add(new_user)
            db.session.commit()
            return redirect('/user')
        else:
            return render_template('create_user.html',
                                   form=form,
                                   error="User already exist")
    elif request.method == 'GET':
        return render_template('create_user.html', form=form)
示例#3
0
def create_people():
    form = UserForm()

    if request.method == 'POST':
        new_people = People(
            people_name=form.people_name.data,
            people_birthday=form.people_birthday.data.strftime("%Y-%m-%d"),
            people_email=form.people_email.data,
            people_phone=form.people_phone.data,
        )
        db.session.add(new_people)
        db.session.commit()
        return redirect('/people')
    elif request.method == 'GET':
        return render_template('create_people.html', form=form)
示例#4
0
def create_user():
    form = UserForm()

    if request.method == 'POST':
        new_user = User(
            user_name=form.user_name.data,
            user_birthday=form.user_birthday.data.strftime("%Y-%m-%d"),
            user_email=form.user_email.data,
            user_phone=form.user_phone.data,
        )
        db.session.add(new_user)
        db.session.commit()
        return redirect('/user')
    elif request.method == 'GET':
        return render_template('create_user.html', form=form)