This is an automated email from the ASF dual-hosted git repository.
tn 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 aa93e75 use custom bootstrap validation
aa93e75 is described below
commit aa93e7568b7b3fdec4dfa4b16f8d68b18d1c1cf6
Author: Thomas Neidhart <[email protected]>
AuthorDate: Tue Apr 1 09:16:39 2025 +0200
use custom bootstrap validation
---
atr/routes/draft.py | 11 ++++----
atr/static/css/atr.css | 1 -
atr/templates/draft-add-files.html | 52 ++++++++++++++++++--------------------
3 files changed, 30 insertions(+), 34 deletions(-)
diff --git a/atr/routes/draft.py b/atr/routes/draft.py
index 19f44e1..f33e0f7 100644
--- a/atr/routes/draft.py
+++ b/atr/routes/draft.py
@@ -225,12 +225,17 @@ async def add_file(session: routes.CommitterSession,
project_name: str, version_
class AddFilesForm(util.QuartFormTyped):
"""Form for adding file(s) to a release candidate."""
- file_name = wtforms.StringField("File name (optional)",
validators=[wtforms.validators.Optional()])
+ file_name = wtforms.StringField("File name (optional)")
file_data = wtforms.MultipleFileField(
"File", validators=[wtforms.validators.InputRequired("File(s) are
required")]
)
submit = wtforms.SubmitField("Add file(s)")
+ def validate_file_name(self, field: wtforms.Field) -> bool:
+ if field.data and len(self.file_data.data) > 1:
+ raise wtforms.validators.ValidationError("File name can only
be used when uploading a single file")
+ return True
+
form = await AddFilesForm.create_form()
if await form.validate_on_submit():
try:
@@ -238,10 +243,6 @@ async def add_file(session: routes.CommitterSession,
project_name: str, version_
if isinstance(form.file_name.data, str) and form.file_name.data:
file_name = pathlib.Path(form.file_name.data)
file_data = form.file_data.data
- if not file_data or len(file_data) == 0:
- raise routes.FlashError("Invalid file upload")
- if file_name is not None and len(file_data) > 1:
- raise routes.FlashError("File name can only be used when
uploading a single file")
await _upload_files(project_name, version_name, file_name,
file_data)
return await session.redirect(
diff --git a/atr/static/css/atr.css b/atr/static/css/atr.css
index 2c6e9c3..1ac5846 100644
--- a/atr/static/css/atr.css
+++ b/atr/static/css/atr.css
@@ -64,7 +64,6 @@ select, input[type="file"] {
input:not([type="submit"]), textarea, select, option {
border-width: 2px !important;
- border-color: #cccccc !important;
}
a {
diff --git a/atr/templates/draft-add-files.html
b/atr/templates/draft-add-files.html
index 990870b..35cd317 100644
--- a/atr/templates/draft-add-files.html
+++ b/atr/templates/draft-add-files.html
@@ -14,41 +14,37 @@
<h1>Add file(s) to {{ project_name }} {{ version_name }}</h1>
<p class="intro">Use this form to add a single file to this candidate
draft.</p>
- {% if form.errors %}
- <h2 class="text-danger">Form errors</h2>
- <div class="error-message mt-3 mb-3">
- {% for field, errors in form.errors.items() %}
- {% for error in errors %}<p class="text-danger mb-1">{{ field }}: {{
error }}</p>{% endfor %}
- {% endfor %}
- </div>
- {% endif %}
-
<form method="post"
enctype="multipart/form-data"
- class="striking py-4 px-5">
+ class="striking py-4 px-5 needs-validation"
+ novalidate>
{{ form.csrf_token }}
<div class="mb-3 pb-3 row border-bottom">
<label for="{{ form.file_name.id }}"
class="col-sm-3 col-form-label text-sm-end">{{
form.file_name.label.text }}:</label>
<div class="col-sm-8">
- {{ form.file_name(class_="form-control") }}
- {% if form.file_name.errors -%}<span class="error-message">{{
form.file_name.errors[0] }}</span>{%- endif %}
- <span id="file_path-help" class="form-text text-muted">Enter the
path where the file should be saved in the release candidate</span>
- </div>
+ {{ form.file_name(class_="form-control" + (" is-invalid" if
form.file_name.errors else "") ) }}
+ <span id="file_path-help" class="form-text text-muted">Enter the path
where the file should be saved in the release candidate</span>
+ {% if form.file_name.errors %}
+ {% for error in form.file_name.errors %}<div
class="invalid-feedback">{{ error }}</div>{% endfor %}
+ {% endif %}
</div>
+ </div>
- <div class="mb-3 pb-3 row border-bottom">
- <label for="{{ form.file_data.id }}"
- class="col-sm-3 col-form-label text-sm-end">{{
form.file_data.label.text }}:</label>
- <div class="col-sm-8">
- {{ form.file_data(class_="form-control") }}
- {% if form.file_data.errors -%}<span class="error-message">{{
form.file_data.errors[0] }}</span>{%- endif %}
- <span id="file_data-help" class="form-text text-muted">Select the
file(s) to upload</span>
- </div>
- </div>
+ <div class="mb-3 pb-3 row border-bottom">
+ <label for="{{ form.file_data.id }}"
+ class="col-sm-3 col-form-label text-sm-end">{{
form.file_data.label.text }}:</label>
+ <div class="col-sm-8">
+ {{ form.file_data(class_="form-control" + (" is-invalid" if
form.file_data.errors else "") ) }}
+ <span id="file_data-help" class="form-text text-muted">Select the
file(s) to upload</span>
+ {% if form.file_data.errors %}
+ {% for error in form.file_data.errors %}<div
class="invalid-feedback">{{ error }}</div>{% endfor %}
+ {% endif %}
+ </div>
+ </div>
- <div class="row">
- <div class="col-sm-9 offset-sm-3">{{ form.submit(class_="btn
btn-primary mt-3") }}</div>
- </div>
- </form>
- {% endblock content %}
+ <div class="row">
+ <div class="col-sm-9 offset-sm-3">{{ form.submit(class_="btn btn-primary
mt-3") }}</div>
+ </div>
+ </form>
+{% endblock content %}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]