Esempio n. 1
0
 def test_edit_monkey_profile(self, test_monkey):
     """Test edit_monkey_profile()."""
     monkey = test_monkey
     old_id = monkey.id
     form = ProfileEditForm()
     form['first_name'].data = 'Bill'
     form['last_name'].data = 'Gates'
     form['email'].data = '*****@*****.**'
     form['date_of_birth'].data = ''
     form['password'].data = 'secret'
     form['confirm'].data = 'secret'
     assert dba.edit_monkey_profile(monkey, form)
     assert monkey.id == old_id
     assert monkey.first_name == 'Bill'
     assert monkey.last_name == 'Gates'
     assert type(monkey.password) == \
         sqlalchemy_utils.types.password.Password
     assert monkey.email == '*****@*****.**'
     assert monkey.age() is None
Esempio n. 2
0
def edit():
    """Edit monkey's own profile."""
    monkey_self = dba.get_monkey_by_id(session['id'])
    if monkey_self is None:
        return redirect(url_for('index'))

    # If no formdata is present in the request, the form is populated
    # from the object:
    form = ProfileEditForm(request.form, monkey_self)

    if request.method == 'POST' and form.validate():
        # Check for email uniqueness by querying for another monkey
        # with the same address:
        if dba.check_unique_email(form['email'].data, monkey_self.id):
            # If no duplicate found:
            if dba.edit_monkey_profile(monkey_self, form):
                flash('Changes saved')
            else:
                flash('Error saving changes!')
        else:
            form.email.errors.append(
                'This e-mail address is registered with another user')

    return render_template('edit.html', form=form, monkey_self=monkey_self)
Esempio n. 3
0
def edit():
    """Edit monkey's own profile."""
    monkey_self = dba.get_monkey_by_id(session['id'])
    if monkey_self is None:
        return redirect(url_for('index'))

    # If no formdata is present in the request, the form is populated
    # from the object:
    form = ProfileEditForm(request.form, monkey_self)

    if request.method == 'POST' and form.validate():
        # Check for email uniqueness by querying for another monkey
        # with the same address:
        if dba.check_unique_email(form['email'].data, monkey_self.id):
            # If no duplicate found:
            if dba.edit_monkey_profile(monkey_self, form):
                flash('Changes saved')
            else:
                flash('Error saving changes!')
        else:
            form.email.errors.append(
                'This e-mail address is registered with another user')

    return render_template('edit.html', form=form, monkey_self=monkey_self)