Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/contentfilter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,28 @@ async def import_json(
return redir_resp


@webapp.post("/remove/all", name="remove_all_urls")
async def clear_urls(
request: Request,
username: str = AuthDependency,
):
redir_resp = RedirectResponse(
request.url_for("settings"), status_code=http.HTTPStatus.FOUND
)
try:
num_urls = len(database)
database.clear()
if num_urls:
flash(
request,
f"Successfully removed {num_urls} blocked URL(s) from the list",
"success",
)
else:
flash(request, "The list was already empty", "info")
except Exception as exc:
flash(request, f"Unable to remove URLs: {exc}.", "danger")
return redir_resp


app.mount(Conf.webroot_prefix, webapp)
6 changes: 6 additions & 0 deletions src/contentfilter/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ <h2>Import from file</h2>
</div>
</form>

<h2 class="mt-4">Delete all URLs</h2>
<p>Remove all blocked URLs from your list. This action cannot be undone.</p>
<form method="POST" action="{{ url_for('remove_all_urls') }}" onsubmit="return confirm('Are you sure you want to delete all blocked URLs? This cannot be undone.');">
<button type="submit" class="btn btn-danger"><i class="bi-trash" role="img"></i> Delete All</button>
</form>

<hr />

<h2>Settings</h2>
Expand Down