From 510176dea3a6c2f75d43085a0d4733c6c67b6c9f Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:18:06 +1300 Subject: [PATCH] form tweaks for accessibility plus admin topic editing --- app/admin/forms.py | 1 + app/admin/routes.py | 4 +++- app/auth/forms.py | 12 ++++++------ app/community/forms.py | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/admin/forms.py b/app/admin/forms.py index dea99c6c..9a9dbd47 100644 --- a/app/admin/forms.py +++ b/app/admin/forms.py @@ -90,6 +90,7 @@ class EditCommunityForm(FlaskForm): class EditTopicForm(FlaskForm): name = StringField(_l('Name'), validators=[DataRequired()]) + machine_name = StringField(_l('Url'), validators=[DataRequired()]) add_community = SelectField(_l('Community to add'), coerce=int, validators=[Optional()]) submit = SubmitField(_l('Save')) diff --git a/app/admin/routes.py b/app/admin/routes.py index 59b13498..9e70f422 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -343,7 +343,7 @@ def admin_topic_add(): form = EditTopicForm() form.add_community.choices = communities_for_form() if form.validate_on_submit(): - topic = Topic(name=form.name.data, num_communities=0) + topic = Topic(name=form.name.data, machine_name=form.machine_name.data, num_communities=0) db.session.add(topic) db.session.commit() if form.add_community.data: @@ -369,6 +369,7 @@ def admin_topic_edit(topic_id): if form.validate_on_submit(): topic.name = form.name.data topic.num_communities = topic.communities.count() + 1 + topic.machine_name = form.machine_name.data if form.add_community.data: community = Community.query.get(form.add_community.data) community.topic_id = topic.id @@ -377,6 +378,7 @@ def admin_topic_edit(topic_id): return redirect(url_for('admin.admin_topics')) else: form.name.data = topic.name + form.machine_name.data = topic.machine_name return render_template('admin/edit_topic.html', title=_('Edit topic'), form=form, topic=topic, moderating_communities=moderating_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id()) diff --git a/app/auth/forms.py b/app/auth/forms.py index 27da7a95..7bd1899a 100644 --- a/app/auth/forms.py +++ b/app/auth/forms.py @@ -6,17 +6,17 @@ from app.models import User, Community class LoginForm(FlaskForm): - user_name = StringField(_l('User name'), validators=[DataRequired()]) + user_name = StringField(_l('User name'), validators=[DataRequired()], render_kw={'autofocus': True, 'autocomplete': 'username'}) password = PasswordField(_l('Password'), validators=[DataRequired()]) low_bandwidth_mode = BooleanField(_l('Low bandwidth mode')) submit = SubmitField(_l('Log In')) class RegistrationForm(FlaskForm): - user_name = StringField(_l('User name'), validators=[DataRequired()]) + user_name = StringField(_l('User name'), validators=[DataRequired()], render_kw={'autofocus': True, 'autocomplete': 'username'}) email = HiddenField(_l('Email')) - real_email = StringField(_l('Email'), validators=[DataRequired(), Email(), Length(min=5, max=255)]) - password = PasswordField(_l('Password'), validators=[DataRequired(), Length(min=8, max=50)]) + real_email = StringField(_l('Email'), validators=[DataRequired(), Email(), Length(min=5, max=255)], render_kw={'autocomplete': 'email'}) + password = PasswordField(_l('Password'), validators=[DataRequired(), Length(min=8, max=50)], render_kw={'autocomplete': 'new-password'}) password2 = PasswordField( _l('Repeat password'), validators=[DataRequired(), EqualTo('password')]) @@ -62,12 +62,12 @@ class RegistrationForm(FlaskForm): class ResetPasswordRequestForm(FlaskForm): - email = StringField(_l('Email'), validators=[DataRequired(), Email()]) + email = StringField(_l('Email'), validators=[DataRequired(), Email()], render_kw={'autofocus': True}) submit = SubmitField(_l('Request password reset')) class ResetPasswordForm(FlaskForm): - password = PasswordField(_l('Password'), validators=[DataRequired()]) + password = PasswordField(_l('Password'), validators=[DataRequired()], render_kw={'autofocus': True}) password2 = PasswordField( _l('Repeat password'), validators=[DataRequired(), EqualTo('password')]) diff --git a/app/community/forms.py b/app/community/forms.py index b00a78fe..27aaf9b0 100644 --- a/app/community/forms.py +++ b/app/community/forms.py @@ -37,7 +37,7 @@ class AddLocalCommunity(FlaskForm): class SearchRemoteCommunity(FlaskForm): - address = StringField(_l('Community address'), render_kw={'placeholder': 'e.g. !name@server'}, validators=[DataRequired()]) + address = StringField(_l('Community address'), render_kw={'placeholder': 'e.g. !name@server', 'autofocus': True}, validators=[DataRequired()]) submit = SubmitField(_l('Search'))