Beispiel #1
0
def new_person():
    form = PersonForm()

    if request.method == 'POST':
        if not form.validate():
            return render_template('person_form.html',
                                   form=form,
                                   form_name="New person",
                                   action="new_person")
        else:
            new_person = user_datastore.create_user(
                username=form.username.data,
                password=form.password.data,
                name=form.name.data,
                surname=form.surname.data,
                email=form.email.data)

            role = db.session.query(ormRole).filter(
                ormRole.name == "User").one()

            new_person.roles.append(role)

            db.session.add(new_person)
            db.session.commit()

            return redirect(url_for('person'))

    return render_template('person_form.html',
                           form=form,
                           form_name="New person",
                           action="new_person")
Beispiel #2
0
def new_person():

    form = PersonForm()

    if request.method == 'POST':
        if form.validate() != False:
            return render_template('person_form.html',
                                   form=form,
                                   form_name="New person",
                                   action="new_person")
        else:
            new_person = ormPersons(
                person_login=form.person_login.data,
                person_password=form.person_password.data,
                person_name=form.person_name.data,
                person_surname=form.person_surname.data,
                person_email=form.person_email.data,
                person_birthday=form.person_birthday.data.strftime("%d-%b-%y"))

            db.session.add(new_person)
            db.session.commit()

            return redirect(url_for('person'))

    return render_template('person_form.html',
                           form=form,
                           form_name="New person",
                           action="new_person")
Beispiel #3
0
def edit_person():

    form = PersonForm()

    if request.method == 'GET':

        person_login = request.args.get('person_login')
        person = db.session.query(ormPersons).filter(
            ormPersons.person_login == person_login).one()

        # fill form and send to user
        form.person_login.data = person.person_login
        form.person_password.data = person.person_password
        form.person_name.data = person.person_name
        form.person_surname.data = person.person_surname
        form.person_email.data = person.person_email
        form.person_birthday.data = person.person_birthday

        return render_template('person_form.html',
                               form=form,
                               form_name="Edit person",
                               action="edit_person")

    else:

        if form.validate() != False:
            return render_template('person_form.html',
                                   form=form,
                                   form_name="Edit person",
                                   action="edit_person")
        else:
            # find user
            person = db.session.query(ormPersons).filter(
                ormPersons.person_login == form.person_login.data).one()

            # update fields from form data
            person.person_login = form.person_login.data
            person.person_password = form.person_password.data
            person.person_name = form.person_name.data
            person.person_surname = form.person_surname.data
            person.person_email = form.person_email.data
            person.person_birthday = form.person_birthday.data.strftime(
                "%d-%b-%y")

            db.session.commit()

            return redirect(url_for('person'))
Beispiel #4
0
def edit_person():
    form = PersonForm()

    if request.method == 'GET':

        person_login = request.args.get('person_login')
        person = db.session.query(ormPersons).filter(
            ormPersons.username == person_login).one()

        # fill form and send to user
        form.username.data = person.username
        form.password.data = person.password
        form.name.data = person.name
        form.surname.data = person.surname
        form.email.data = person.email

        return render_template('person_form.html',
                               form=form,
                               form_name="Edit person",
                               action="edit_person")

    else:

        if not form.validate():
            return render_template('person_form.html',
                                   form=form,
                                   form_name="Edit person",
                                   action="edit_person")
        else:
            # find user
            person = db.session.query(ormPersons).filter(
                ormPersons.username == form.username.data).one()

            # update fields from form data
            person.username = form.username.data
            person.password = form.password.data
            person.name = form.name.data
            person.surname = form.surname.data
            person.email = form.email.data

            db.session.commit()

            return redirect(url_for('person'))
Beispiel #5
0
def edit_person():
    form = PersonForm()

    if request.method == 'GET':

        person_id = request.args.get('person_id')
        person = db.session.query(OrmUser).filter(
            OrmUser.id == person_id).one()

        form.person_id.data = person_id
        form.person_username.data = person.username
        form.person_email.data = person.email
        form.person_password.data = person.password
        form.person_name.data = person.name
        form.person_surname.data = person.surname
        form.person_card.data = person.card

        return render_template('person_form.html',
                               form=form,
                               form_name="Edit person",
                               action="edit_person")

    else:

        if not form.validate():
            return render_template('person_form.html',
                                   form=form,
                                   form_name="Edit person",
                                   action="edit_person")
        else:
            person = db.session.query(OrmUser).filter(
                OrmUser.id == form.person_id.data).one()

            person.email = form.person_email.data
            person.username = form.person_username.data,
            person.password = hash_password(form.person_password.data)
            person.name = form.person_name.data
            person.surname = form.person_surname.data
            person.card = form.person_card.data

            db.session.commit()

            return redirect(url_for('person'))