This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-release.git
The following commit(s) were added to refs/heads/main by this push:
new a625b7c Add a macro for rendering form inputs
a625b7c is described below
commit a625b7cb64f702b688a67254c8c84e6f03122037
Author: Sean B. Palmer <[email protected]>
AuthorDate: Mon May 12 20:34:54 2025 +0100
Add a macro for rendering form inputs
---
Makefile | 2 +-
atr/routes/projects.py | 13 ++++++++++---
atr/templates/layouts/base.html | 1 +
atr/templates/macros/forms.html | 29 +++++++++++++++++++++++++++++
atr/templates/release-policy-form.html | 31 +++++++++++++------------------
5 files changed, 54 insertions(+), 22 deletions(-)
diff --git a/Makefile b/Makefile
index c88b1e7..6dd33d9 100644
--- a/Makefile
+++ b/Makefile
@@ -73,7 +73,7 @@ serve:
--keyfile key.pem --certfile cert.pem atr.server:app --debug --reload
serve-local:
- APP_HOST=127.0.0.1:8080 LOCAL_DEBUG=1 \
+ APP_HOST=127.0.0.1:8080 LOCAL_DEBUG=1 SECRET_KEY=insecure-local-key \
SSH_HOST=127.0.0.1 $(SCRIPTS)/run hypercorn --bind $(BIND) \
--keyfile key.pem --certfile cert.pem atr.server:app --debug --reload
diff --git a/atr/routes/projects.py b/atr/routes/projects.py
index 672bbd0..f6165a0 100644
--- a/atr/routes/projects.py
+++ b/atr/routes/projects.py
@@ -56,6 +56,7 @@ class ReleasePolicyForm(util.QuartFormTyped):
wtforms.validators.InputRequired("Please provide a valid email
address"),
wtforms.validators.Email(),
],
+ render_kw={"size": 30},
),
min_entries=1,
)
@@ -68,9 +69,15 @@ class ReleasePolicyForm(util.QuartFormTyped):
default=72,
)
manual_vote = wtforms.BooleanField("Voting process:")
- release_checklist = wtforms.StringField("Release checklist:",
widget=wtforms.widgets.TextArea())
- start_vote_template = wtforms.StringField("Start vote template:",
widget=wtforms.widgets.TextArea())
- announce_release_template = wtforms.StringField("Announce release
template:", widget=wtforms.widgets.TextArea())
+ release_checklist = wtforms.StringField(
+ "Release checklist:", widget=wtforms.widgets.TextArea(),
render_kw={"rows": 10}
+ )
+ start_vote_template = wtforms.StringField(
+ "Start vote template:", widget=wtforms.widgets.TextArea(),
render_kw={"rows": 10}
+ )
+ announce_release_template = wtforms.StringField(
+ "Announce release template:", widget=wtforms.widgets.TextArea(),
render_kw={"rows": 10}
+ )
pause_for_rm = wtforms.BooleanField("Pause for RM:")
submit = wtforms.SubmitField("Save")
diff --git a/atr/templates/layouts/base.html b/atr/templates/layouts/base.html
index 2514c46..6074860 100644
--- a/atr/templates/layouts/base.html
+++ b/atr/templates/layouts/base.html
@@ -45,6 +45,7 @@
{% endif %}
{% from "macros/flash.html" import render_flash_messages %}
{{ render_flash_messages() }}
+ {% import 'macros/forms.html' as forms %}
{% block content %}
{% endblock content %}
</main>
diff --git a/atr/templates/macros/forms.html b/atr/templates/macros/forms.html
new file mode 100644
index 0000000..aaaeb67
--- /dev/null
+++ b/atr/templates/macros/forms.html
@@ -0,0 +1,29 @@
+{% macro render_field(field, label=False, class_='form-control') %}
+ {% if label and field.label %}{{ field.label(class="form-label") }}{% endif
%}
+ {% set field_class = class_ + (' is-invalid' if field.errors else '') %}
+ {{ field(class_=field_class) }}
+ {% if field.errors %}
+ <div class="invalid-feedback">
+ {% for error in field.errors %}
+ {{ error }}
+ {% if not loop.last %}<br />{% endif %}
+ {% endfor %}
+ </div>
+ {% endif %}
+ {% if field.description %}<div class="form-text text-muted">{{
field.description }}</div>{% endif %}
+{% endmacro %}
+
+{% macro render_checkbox(field, label=False, class_='form-check-input') %}
+ {% set field_class = class_ + (' is-invalid' if field.errors else '') %}
+ {{ field(class_=field_class) }}
+ {% if label and field.label %}{{ field.label(class="form-check-label") }}{%
endif %}
+ {% if field.errors %}
+ <div class="invalid-feedback d-block">
+ {% for error in field.errors %}
+ {{ error }}
+ {% if not loop.last %}<br />{% endif %}
+ {% endfor %}
+ </div>
+ {% endif %}
+ {% if field.description %}<div class="form-text text-muted">{{
field.description }}</div>{% endif %}
+{% endmacro %}
diff --git a/atr/templates/release-policy-form.html
b/atr/templates/release-policy-form.html
index b170197..7d38b9f 100644
--- a/atr/templates/release-policy-form.html
+++ b/atr/templates/release-policy-form.html
@@ -1,4 +1,3 @@
-
<form method="post"
enctype="multipart/form-data"
class="atr-canary py-4 px-5"
@@ -17,10 +16,7 @@
<label for="{{ form.mailto_addresses.entries[0].id }}"
class="col-sm-3 col-form-label text-sm-end">{{
form.mailto_addresses.entries[0].label.text }}:</label>
<div class="col-sm-8">
- {{ form.mailto_addresses.entries[0](size=30, class_="form-control" + ("
is-invalid" if form.mailto_addresses[0].errors else "")) }}
- {% if form.mailto_addresses[0].errors %}
- {% for error in form.mailto_addresses[0].errors %}<div
class="invalid-feedback">{{ error }}</div>{% endfor %}
- {% endif %}
+ {{ forms.render_field(form.mailto_addresses.entries[0]) }}
<span class="form-text text-muted">Note: This field determines where
vote and finished release announcement emails are sent. You can set this value
to your own mailing list, but ATR will currently only let you send to
<code>[email protected]</code>.</span>
</div>
<!--
@@ -34,9 +30,10 @@
<label for="{{ form.manual_vote.id }}"
class="col-sm-3 col-form-label text-sm-end">{{
form.manual_vote.label.text }}</label>
<div class="col-sm-8">
- {{ form.manual_vote(class_="form-check-input") }}
- <label class="form-check-label">Manual</label>
- <br />
+ <div class="form-check">
+ {{ forms.render_checkbox(form.manual_vote) }}
+ <label class="form-check-label" for="{{ form.manual_vote.id
}}">Manual</label>
+ </div>
<span id="manual_vote-help" class="form-text text-muted">If this is set
then the vote will be completely manual and following policy is ignored.</span>
</div>
</div>
@@ -45,11 +42,8 @@
<label for="{{ form.min_hours.id }}"
class="col-sm-3 col-form-label text-sm-end">{{
form.min_hours.label.text }}</label>
<div class="col-sm-8">
- {{ form.min_hours(class_="form-control" + (" is-invalid" if
form.min_hours.errors else "") ) }}
+ {{ forms.render_field(form.min_hours) }}
<span id="min_hours-help" class="form-text text-muted">The minimum time
to run the vote, in hours. Must be 0 or between 72 and 144 inclusive. If 0,
then wait until 3 +1 votes and more +1 than -1.</span>
- {% if form.min_hours.errors %}
- {% for error in form.min_hours.errors %}<div
class="invalid-feedback">{{ error }}</div>{% endfor %}
- {% endif %}
</div>
</div>
@@ -57,7 +51,7 @@
<label for="{{ form.release_checklist.id }}"
class="col-sm-3 col-form-label text-sm-end">{{
form.release_checklist.label.text }}</label>
<div class="col-sm-8">
- {{ form.release_checklist(rows=10, class_="form-control") }}
+ {{ forms.render_field(form.release_checklist) }}
<span id="release_checklist-help" class="form-text text-muted">Markdown
text describing how to test release candidates.</span>
</div>
</div>
@@ -66,7 +60,7 @@
<label for="{{ form.start_vote_template.id }}"
class="col-sm-3 col-form-label text-sm-end">{{
form.start_vote_template.label.text }}</label>
<div class="col-sm-8">
- {{ form.start_vote_template(rows=10, class_="form-control") }}
+ {{ forms.render_field(form.start_vote_template) }}
<span id="start_vote_template-help" class="form-text text-muted">Email
template for messages to start a vote on a release.</span>
</div>
</div>
@@ -75,7 +69,7 @@
<label for="{{ form.announce_release_template.id }}"
class="col-sm-3 col-form-label text-sm-end">{{
form.announce_release_template.label.text }}</label>
<div class="col-sm-8">
- {{ form.announce_release_template(rows=10, class_="form-control") }}
+ {{ forms.render_field(form.announce_release_template) }}
<span id="announce_release_template-help" class="form-text
text-muted">Email template for messages to announce a finished release.</span>
</div>
</div>
@@ -84,9 +78,10 @@
<label for="{{ form.pause_for_rm.id }}"
class="col-sm-3 col-form-label text-sm-end">{{
form.pause_for_rm.label.text }}</label>
<div class="col-sm-8">
- {{ form.pause_for_rm(class_="form-check-input") }}
- <label class="form-check-label">Enabled</label>
- <br />
+ <div class="form-check">
+ {{ forms.render_checkbox(form.pause_for_rm) }}
+ <label class="form-check-label" for="{{ form.pause_for_rm.id
}}">Enabled</label>
+ </div>
<span id="pause_for_rm-help" class="form-text text-muted">If enabled, RM
can confirm manually if the vote has passed.</span>
</div>
</div>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]