コード例 #1
0
ファイル: profile.py プロジェクト: haseebgit/lastuser
def profile_edit(newprofile=False):
    form = ProfileForm(obj=g.user)
    form.fullname.description = app.config.get('FULLNAME_REASON')
    form.email.description = app.config.get('EMAIL_REASON')
    form.username.description = app.config.get('USERNAME_REASON')
    form.description.description = app.config.get('BIO_REASON')
    form.timezone.description = app.config.get('TIMEZONE_REASON')
    if g.user.email or newprofile is False:
        del form.email

    if form.validate_on_submit():
        # Can't auto-populate here because user.email is read-only
        g.user.fullname = form.fullname.data
        g.user.username = form.username.data
        g.user.description = form.description.data
        g.user.timezone = form.timezone.data

        if newprofile and not g.user.email:
            useremail = UserEmailClaim(user=g.user, email=form.email.data)
            db.session.add(useremail)
            send_email_verify_link(useremail)
            db.session.commit()
            flash(
                "Your profile has been updated. We sent you an email to confirm your address",
                category='success')
        else:
            db.session.commit()
            flash("Your profile has been updated.", category='success')

        if newprofile:
            return render_redirect(get_next_url(), code=303)
        else:
            return render_redirect(url_for('profile'), code=303)
    if newprofile:
        return render_form(
            form,
            title="Update profile",
            formid="profile_new",
            submit="Continue",
            message=
            u"Hello, %s. Please spare a minute to fill out your profile." %
            g.user.fullname,
            ajax=True)
    else:
        return render_form(form,
                           title="Edit profile",
                           formid="profile_edit",
                           submit="Save changes",
                           ajax=True)
コード例 #2
0
def profile_edit():
    form = ProfileForm(obj=g.user)
    form.fullname.description = app.config.get('FULLNAME_REASON')
    form.username.description = app.config.get('USERNAME_REASON')
    form.description.description = app.config.get('BIO_REASON')
    if form.validate_on_submit():
        form.populate_obj(g.user)
        db.session.commit()

        flash("Your profile was successfully edited.", category='success')
        return render_redirect(url_for('profile'), code=303)
    return render_form(form,
                       title="Edit profile",
                       formid="profile_edit",
                       submit="Save changes",
                       ajax=True)