From e8880e73a23571acf47845b1e38292239c5d71b2 Mon Sep 17 00:00:00 2001 From: Matt Arnold Date: Tue, 15 Apr 2025 09:58:58 -0400 Subject: finally got different profiles/faccets to work. Unsure if it was just the typo in the template or we really needed backend changes but belt and suspenders logic applies --- forms.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'forms.py') diff --git a/forms.py b/forms.py index be0171a..ba427cd 100644 --- a/forms.py +++ b/forms.py @@ -1,13 +1,28 @@ from flask_wtf import FlaskForm -from wtforms import StringField, TextAreaField, SubmitField, PasswordField, BooleanField +from wtforms import ( + StringField, + TextAreaField, + SubmitField, + PasswordField, + BooleanField, + SelectField, +) from wtforms.validators import DataRequired class PostForm(FlaskForm): title = StringField("Title", validators=[DataRequired()]) content = TextAreaField("Content", validators=[DataRequired()]) + faccets = SelectField("Faccet", coerce=int) submit = SubmitField("Toot!") + def __init__(self, *args, **kwargs): + super(PostForm, self).__init__(*args, **kwargs) + # Populate the select field with profile from the database + self.faccets.choices = [(0, "Please select a profile")] + [ + (u.id, u.name) for u in kwargs["faccets"] + ] + class LoginForm(FlaskForm): """Login Form""" -- cgit 1.4.1-2-gfad0