From a0fcb78e95e4585fc358fe94af3735e2f39332d0 Mon Sep 17 00:00:00 2001
From: Martin Green <martin.speleo@gmail.com>
Date: Wed, 5 Jul 2023 18:21:15 +0100
Subject: [PATCH] Removed kataster area for unoffical numbers of pending caves.
  Added .html to urls of pending caves.

---
 parsers/caves.py | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/parsers/caves.py b/parsers/caves.py
index 06b77c9..5c6b5ac 100644
--- a/parsers/caves.py
+++ b/parsers/caves.py
@@ -146,10 +146,10 @@ def create_new_cave(svxpath):
     # double check
     if a[0:3] == "162":
         areanum = a[0:4]
-        url = f"{areanum}/{a[5:]}"  # Note we are not appending the .htm as we are modern folks now.
+        url = f"{areanum}/{a[5:]}.html"  # Note we are appending the .html as we are believe in backwards compatability.
     else:
         areanum = "1623"
-        url = f"1623/{k}"
+        url = f"1623/{k}.html"
         
     k = f"{areanum}-{caveid}"
     area = get_area(areanum)
@@ -162,7 +162,7 @@ def create_new_cave(svxpath):
         return caves[0]
 
     try:
-        cave = do_pending_cave(k, url, area)
+        cave = do_pending_cave(k, caveid, url, area)
     except:
         message = f" ! Error. Cannot create pending cave and entrance, pending-id:{k} in area {areanum}"
         DataIssue.objects.create(parser="caves", message=message)
@@ -174,7 +174,7 @@ def create_new_cave(svxpath):
     cave.save()
     return cave
 
-def do_pending_cave(k, url, area):
+def do_pending_cave(k, caveid, url, area):
     """
     default for a PENDING cave, should be overwritten in the db later if a real cave of the same name exists
     in expoweb/cave_data/1623-"k".html
@@ -266,7 +266,7 @@ def do_pending_cave(k, url, area):
         survex_file = get_survex_file(k)
 
         cave = Cave(
-            unofficial_number=k,
+            unofficial_number=caveid,
             underground_description="Pending cave write-up - creating as empty object. No XML file available yet.",
             survex_file=survex_file,
             url=url,
@@ -718,14 +718,16 @@ def readcaves():
 
             if k[0:3] == "162":
                 areanum = k[0:4]
-                url = f"{areanum}/{k[5:]}"  # Note we are not appending the .htm as we are modern folks now.
+                number = k[5:]
+                url = f"{areanum}/{k[5:]}.html"  # Note we are appending the .htm to allow for offline websites
             else:
                 areanum = "1623"
+                number = k
                 url = f"1623/{k}"
 
             area = get_area(areanum)
             try:
-                do_pending_cave(k, url, area)
+                do_pending_cave(k, number, url, area)
             except:
                 message = f" ! Error. Cannot create pending cave and entrance, pending-id:{k} in area {areanum}"
                 DataIssue.objects.create(parser="caves", message=message)