You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by sb...@apache.org on 2025/07/31 18:20:00 UTC
(tooling-trusted-release) branch main updated: Add a form to delete check result ignores
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 3f2a96f Add a form to delete check result ignores
3f2a96f is described below
commit 3f2a96f9f8dba2ddfb0e6146742816787d2939c5
Author: Sean B. Palmer <se...@miscoranda.com>
AuthorDate: Thu Jul 31 19:19:41 2025 +0100
Add a form to delete check result ignores
---
atr/forms.py | 33 +++++++++++++++++++-------
atr/routes/ignores.py | 65 +++++++++++++++++++++++++++++++++++++++++----------
2 files changed, 78 insertions(+), 20 deletions(-)
diff --git a/atr/forms.py b/atr/forms.py
index 06163bd..e73e8ef 100644
--- a/atr/forms.py
+++ b/atr/forms.py
@@ -199,38 +199,55 @@ def radio(label: str, optional: bool = False, validators: list[Any] | None = Non
return wtforms.RadioField(label, validators=validators, **kwargs)
-def render(form: Typed, action: str) -> htpy.Element:
+def render(
+ form: Typed,
+ action: str,
+ form_classes: str = ".atr-canary",
+ submit_classes: str = "btn-primary",
+ columns: bool = True,
+) -> htpy.Element:
hidden_elems: list[markupsafe.Markup] = []
field_rows: list[htpy.Element] = []
submit_row: htpy.Element | None = None
+ label_class = "col-sm-3 col-form-label text-sm-end" if columns else "text-sm-end"
for field in form:
if isinstance(field, wtforms.HiddenField):
hidden_elems.append(markupsafe.Markup(str(field)))
continue
+
if isinstance(field, wtforms.StringField):
widget = markupsafe.Markup(str(field(class_="form-control")))
- label_html = markupsafe.Markup(str(field.label(class_="col-sm-3 col-form-label text-sm-end")))
- row = htpy.div(".mb-3 row")[label_html, htpy.div(".col-sm-8")[widget]]
+ label_html = markupsafe.Markup(str(field.label(class_=label_class)))
+ row_class = ".mb-3.row" if columns else ".row"
+ widget_class = ".col-sm-8" if columns else ""
+ row = htpy.div(row_class)[label_html, htpy.div(widget_class)[widget]]
field_rows.append(row)
continue
+
if isinstance(field, wtforms.SelectField):
widget = markupsafe.Markup(str(field(class_="form-select")))
- label_html = markupsafe.Markup(str(field.label(class_="col-sm-3 col-form-label text-sm-end")))
- row = htpy.div(".mb-3 row")[label_html, htpy.div(".col-sm-8")[widget]]
+ label_html = markupsafe.Markup(str(field.label(class_=label_class)))
+ row_class = ".mb-3.row" if columns else ".row"
+ widget_class = ".col-sm-8" if columns else ""
+ row = htpy.div(row_class)[label_html, htpy.div(widget_class)[widget]]
field_rows.append(row)
continue
+
if isinstance(field, wtforms.SubmitField):
- button_html = markupsafe.Markup(str(field(class_="btn btn-primary mt-2")))
- submit_row = htpy.div(".row")[htpy.div(".col-sm-9 offset-sm-3")[button_html]]
+ button_class = "btn " + submit_classes
+ button_html = markupsafe.Markup(str(field(class_=button_class)))
+ div_class = ".col-sm-9.offset-sm-3" if columns else ""
+ submit_row = htpy.div(".row")[htpy.div(div_class)[button_html]]
continue
+
raise TypeError(f"Unsupported field type: {type(field).__name__}")
form_children: list[htpy.Element | markupsafe.Markup] = hidden_elems + field_rows
if submit_row is not None:
form_children.append(submit_row)
- return htpy.form(".atr-canary", action=action, method="post")[form_children]
+ return htpy.form(form_classes, action=action, method="post")[form_children]
def select(
diff --git a/atr/routes/ignores.py b/atr/routes/ignores.py
index 4b88bce..227c795 100644
--- a/atr/routes/ignores.py
+++ b/atr/routes/ignores.py
@@ -83,6 +83,11 @@ class AddIgnoreForm(forms.Typed):
# TODO: Validate that at least one field is set
+class DeleteIgnoreForm(forms.Typed):
+ id = forms.hidden()
+ submit = forms.submit("Delete")
+
+
@routes.committer("/ignores/<committee_name>", methods=["GET", "POST"])
async def ignores(session: routes.CommitterSession, committee_name: str) -> str | response.Response:
async with storage.read(session.asf_uid) as read:
@@ -94,7 +99,7 @@ async def ignores(session: routes.CommitterSession, committee_name: str) -> str
p[f"Manage ignored checks for committee {committee_name}."],
_add_ignore(committee_name),
_existing_ignores(ignores),
- _script(_UPDATE_IGNORE_FORM),
+ _script_dom_loaded(_UPDATE_IGNORE_FORM),
]
return await template.blank("Ignored checks", content)
@@ -128,11 +133,51 @@ async def ignores_committee_add(session: routes.CommitterSession, committee_name
)
+@routes.committer("/ignores/<committee_name>/delete", methods=["POST"])
+async def ignores_committee_delete(session: routes.CommitterSession, committee_name: str) -> str | response.Response:
+ data = await quart.request.form
+ form = await DeleteIgnoreForm.create_form(data=data)
+ if not (await form.validate_on_submit()):
+ return await session.redirect(
+ ignores,
+ committee_name=committee_name,
+ error="Form validation errors",
+ )
+
+ if not isinstance(form.id.data, str):
+ return await session.redirect(
+ ignores,
+ committee_name=committee_name,
+ error="Invalid ignore ID",
+ )
+
+ cri_id = int(form.id.data)
+ async with storage.write(session.asf_uid) as write:
+ wacm = write.as_committee_member(committee_name)
+ await wacm.checks.ignore_delete(id=cri_id)
+
+ return await session.redirect(
+ ignores,
+ committee_name=committee_name,
+ success="Ignore deleted",
+ )
+
+
def _check_result_ignore_card(cri: sql.CheckResultIgnore) -> htpy.Element:
card_header_h3 = h3(".mb-0")[f"{cri.id or ''} - {cri.asf_uid} - {util.format_datetime(cri.created)}"]
table_rows = []
+ form = DeleteIgnoreForm(id=cri.id)
+ form_path = util.as_url(ignores_committee_delete, committee_name=cri.committee_name)
+ delete_ignore_form = forms.render(
+ form,
+ form_path,
+ form_classes="",
+ submit_classes="btn-danger",
+ columns=False,
+ )
+
def add_row(label: str, value: str | None) -> None:
nonlocal table_rows
if value is not None:
@@ -140,10 +185,7 @@ def _check_result_ignore_card(cri: sql.CheckResultIgnore) -> htpy.Element:
tr[
th[label],
td[input(".form-control.form-control-sm", data_value=value, value=value)],
- td[
- button(".btn.btn-primary.btn-sm.me-4.disabled")["Update"],
- button(".btn.btn-danger.btn-sm")["Delete"],
- ],
+ td[button(".btn.btn-primary.btn-sm.me-4.disabled")["Update"],],
]
)
@@ -159,7 +201,7 @@ def _check_result_ignore_card(cri: sql.CheckResultIgnore) -> htpy.Element:
card = div(".card")[
div(".card-header")[card_header_h3],
- div(".card-body")[table_striped, p[button(".btn.btn-danger.btn-sm")["Delete"]]],
+ div(".card-body")[table_striped, delete_ignore_form],
]
return card
@@ -177,15 +219,14 @@ def _add_ignore(committee_name: str) -> htpy.Element:
def _existing_ignores(ignores: list[sql.CheckResultIgnore]) -> htpy.Element:
return div[
h2["Existing ignores"],
- [_check_result_ignore_card(cri) for cri in ignores],
+ [_check_result_ignore_card(cri) for cri in ignores] or p["No ignores found."],
]
-def _script(text: str) -> htpy.Element:
- return script[
- markupsafe.Markup(f"""
+def _script_dom_loaded(text: str) -> htpy.Element:
+ script_text = markupsafe.Markup(f"""
document.addEventListener("DOMContentLoaded", function () {{
- {text}
+{text}
}});
""")
- ]
+ return script[script_text]
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org