Beispiel #1
0
def profile_new():
    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:
        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 not g.user.email:
            useremail = UserEmailClaim(user=g.user, email=form.email.data)
            db.session.add(useremail)
            db.session.commit()
            send_email_verify_link(useremail)
            flash("Your profile was successfully updated. We sent you an email to confirm your address", category='success')
        else:
            db.session.commit()
            flash("Your profile was successfully updated.", category='success')

        return render_redirect(get_next_url(), code=303)
    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)
Beispiel #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)
Beispiel #3
0
def profile_edit():
    form = ProfileForm(obj=g.user)
    form.edit_obj = g.user
    if form.validate_on_submit():
        form.populate_obj(g.user)
        db.session.commit()

        next_url = get_next_url()
        if next_url is not None:
            return render_redirect(next_url)
        else:
            flash("Your profile was successfully edited.", category="info")
            return render_redirect(url_for("profile"), code=303)
    return render_form(form, title="Edit profile", formid="profile_edit", submit="Save changes", ajax=True)
Beispiel #4
0
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)
Beispiel #5
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)
Beispiel #6
0
def profile_edit():
    form = ProfileForm()
    if request.method == 'GET':
        form.fullname.data = g.user.fullname
        form.username.data = g.user.username
        form.description.data = g.user.description
    elif form.validate_on_submit():
        g.user.fullname = form.fullname.data
        g.user.username = form.username.data or None
        g.user.description = form.description.data
        db.session.commit()

        next_url = get_next_url()
        if(next_url is not None):
            return render_redirect(next_url)
        else:
            flash("Your profile was successfully edited.", category='info')
            return render_redirect(url_for('profile'), code=303)
    return render_form(form, title="Edit profile", formid="profile_edit", submit="Save changes", ajax=True)