Esempio n. 1
0
def pref():
    form = PreferencesForm()
    if (request.method == 'POST'):
        if (form.validate() == False):
            flash('Please fill all the weightages correctly')
            return render_template('pref.html', form=form)
        else:
            return render_template('base.html')
    else:
        return render_template('pref.html', form=form)
    return render_template('pref.html')
Esempio n. 2
0
def preferences(token,
                header="Update your preferences",
                subheader="Customize your weather window"):
    email = auth.decode_token_to_email(token)
    form = PreferencesForm()

    if request.method == 'POST':
        try:
            form.validate()
            actions.update_preferences_for_user_from_form(email, form=form)
            flash(
                f"We've updated your preferences, thanks. You'll see this reflected in the next "
                f"weather window we send you!")
            return redirect(url_for('api.index'))
        except ValidationError as error:
            flash(error, category='error')

    form.initialize_from_db(actions.add_or_return_user_preferences(email))
    return render_template('confirm.html',
                           title='Weather Window: Preferences',
                           header=header,
                           subheader=subheader,
                           form=form)