示例#1
0
def update_time_zone():
    form = UserTimeZoneForm(request.form, obj=g.user)

    if form.validate_on_submit():
        form.populate_obj(g.user)
        db.session.commit()
        babel_refresh()
        flash(u'Your time zone was successfully updated.', 'success')

        now = to_user_timezone(datetime.utcnow())
        user_tz_names = (format_datetime(now, 'zzzz'), format_datetime(now, 'zzz'))

        return jsonify(success=True, time_zone=form.time_zone.data,
                csrf=form.csrf_token.data, user_tz_names=user_tz_names)

    flash(u'There was an error updating your time zone.', 'error')
    return jsonify(success=False)
示例#2
0
def settings():
    emails = set()
    for u in User.query.all():
        if u.email is not None:
            emails.add(u.email.lower())

    if g.user.email is not None:
        email_lower = g.user.email.lower()
        if email_lower in emails:
            emails.remove(email_lower)

    form = UserSettingsForm(request.form, obj=g.user)
    form.email.validators[0].values = emails

    if form.validate_on_submit():
        form.populate_obj(g.user)
        db.session.commit()
        babel_refresh()
        flash(u'Your settings were successfully updated.', 'success')
        return redirect(url_for('settings'))

    return rt('account/create.html', settings=True, form=form)