Пример #1
0
 def test_validate_gender_missing(self, person):
     form = ProfileForm(
         formdata=MultiDict({
             'name': 'foo',
             'preferred_contact': 'email',
         }),
         meta={'csrf': False},
     )
     assert form.validate() is False
Пример #2
0
def profile():
    form=ProfileForm(old_obj=current_user,obj=current_user)
    
    if form.validate_on_submit():
        current_user.username=form.username.data
        current_user.email=form.email.data
        db.session.commit()
        flash('Your changes were saved.','success')
        return redirect(url_for('main.index'))
    return render_template('auth/profile.html', user=current_user, title='Profile', form=form)
Пример #3
0
 def test_validate_success(self, person):
     form = ProfileForm(
         formdata=MultiDict({
             'name': 'foo',
             'preferred_contact': 'email',
             'gender': 'Self-described',
             'gender_self_describe': 'my-description',
         }),
         meta={'csrf': False},
     )
     assert form.validate() is True
Пример #4
0
def profile():
    form = ProfileForm()
    if form.validate_on_submit():
        # добавляем данные текущего пользователя
        redis_store.hset(current_user.id, 'username', form.username.data)
        redis_store.hset(current_user.id, 'role', form.role.data)
        flash('Данные сохранены!')
        return redirect(url_for('auth.profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.role.data = current_user.role
    return render_template('auth/profile.html', form=form)
Пример #5
0
 def test_validate_gender_self_describe_no_description(self, person):
     form = ProfileForm(
         formdata=MultiDict({
             'name': 'foo',
             'preferred_contact': 'email',
             'gender': 'Self-described',
         }),
         meta={'csrf': False},
     )
     assert form.validate() is False
     assert len(form.errors['gender']) == 1
     assert "You selected Self-described but didn't self-describe" == form.errors['gender'][0]
Пример #6
0
 def test_validate_contact_phone_no_number(self, person):
     form = ProfileForm(
         formdata=MultiDict({
             'name': 'foo',
             'preferred_contact': 'phone',
             'gender': 'Self-described',
         }),
         meta={'csrf': False},
     )
     assert form.validate() is False
     assert len(form.errors['phone_number']) == 1
     assert "You must enter a phone number" in form.errors['phone_number'][0]
Пример #7
0
def profile():
    form = ProfileForm()
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.location = form.location.data
        current_user.bio = form.bio.data
        db.session.add(current_user._get_current_object())
        db.session.commit()
        flash('Your profile has been updated.')
        return redirect(url_for('talks.user', username=current_user.username))
    form.name.data = current_user.name
    form.location.data = current_user.location
    form.bio.data = current_user.bio
    return render_template('talks/profile.html', form=form)
Пример #8
0
 def post(self):
     form = ProfileForm()
     if form.validate_on_submit():
         username = form.data['username']
         user = User.query.filter_by(user_name=func.binary(username)).first()
         user.email = form.email.data
         user.password = form.password.data
         user.real_name = form.name.data
         user.update_time = datetime.now()
         db.session.add(user)
         db.session.commit()
         flash("个人资料修改成功!")
     else:
         flash(form.errors.popitem()[1][0])
     return render_template("auth/profile.html", form=form)
Пример #9
0
 def get(self):
     form = ProfileForm()
     user = User.query.filter_by(user_name=func.binary(current_user.user_name)).first()
     form.username.data = current_user.user_name
     # form.password.data = user.password
     form.name.data =  user.real_name
     form.email.data = user.email
     form.rolename.data = ','.join([role.role_name for role in user.roles])
     return render_template("auth/profile.html", form = form)