From 2e3d1521e34e56216cfbf4dc3725d41f1ed65780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Valenta?= <git@imaniti.org> Date: Fri, 21 Apr 2023 00:12:08 +0200 Subject: [PATCH] normalize path --- contracts/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/contracts/views.py b/contracts/views.py index 21f3a5c..d8e6fba 100644 --- a/contracts/views.py +++ b/contracts/views.py @@ -1,3 +1,5 @@ +import os + from xml.etree import ElementTree import requests @@ -427,11 +429,14 @@ def get_ares_info(request, ico: int): def handle_404(request, exception): - path = request.get_full_path() + path = os.path.normpath(request.get_full_path()) archive_url = f"https://smlouvy-archiv.pirati.cz{path}" archive_response = requests.get(archive_url) + # Quick dirty check for whether the page found is an actual contract + was_found = archive_response.ok and "Datum podpisu" in str(archive_response.content) + return render( request, "contracts/404.html", @@ -439,7 +444,7 @@ def handle_404(request, exception): **get_base_context(request), "title": "Stránka nenalezena", "description": "", - "archive_page_exists": archive_response.ok, + "archive_page_exists": was_found, "archive_url": archive_url, } ) -- GitLab