summaryrefslogtreecommitdiffstats
path: root/parsers/survex.py
diff options
context:
space:
mode:
Diffstat (limited to 'parsers/survex.py')
-rw-r--r--parsers/survex.py35
1 files changed, 33 insertions, 2 deletions
diff --git a/parsers/survex.py b/parsers/survex.py
index 7f7c902..76acda6 100644
--- a/parsers/survex.py
+++ b/parsers/survex.py
@@ -12,7 +12,7 @@ from django.utils.timezone import get_current_timezone
from django.utils.timezone import make_aware
import troggle.settings as settings
-from troggle.core.models.caves import Entrance, QM
+from troggle.core.models.caves import Entrance, QM, LogbookEntry
from troggle.core.utils import get_process_memory, chaosmonkey
from troggle.parsers.people import GetPersonExpeditionNameLookup
from troggle.parsers.logbooks import GetCaveLookup
@@ -529,13 +529,44 @@ class LoadingSurvex():
# NB none of the SurveyStations are in the DB now, so if we want to link to aSurvexStation
# we would have to create one. But that is not obligatory and no QMs loaded from CSVs have one
+
+ # Older troggle/CSV assumes a logbook entry 'found_by' for each QM, with a date.
+ # We have a date from the survexfile. This is needed for the absolute_url resolution..
+
+ # We don't know if the survexfile has an associated logbook entry as there is no direct link
+ # so we create a dummy one anyway. We should make logbook entry links optional in QMs in future and
+ # remove this hack.
+ qmyear = str(survexblock.date)[:4]
+ logslug = f'DUM_{int(qmyear)}_{int(qm_no):03d}'
+ if survexblock.survexfile.cave:
+ caveslug = survexblock.survexfile.cave.slug()
+ place = survexblock.survexfile.cave
+ else:
+ caveslug = "ugh"
+ place = "oops"
+
+
+ message = f' ! - logbook dummy "{logslug}" {str(survexblock.date)[:11]} for cave "{caveslug}" created.'
+
+ placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=qmyear,
+ place=place,
+ title="placeholder for survex QM",
+ text=message,
+ entry_type="DUMMY",
+ expedition_id=1,
+ defaults={"date": survexblock.date,"cave_slug":caveslug, "slug": logslug})
+ print(insp+message)
+ DataIssue.objects.create(parser='survex', message=message)
+
try:
qm = QM.objects.create(number=qm_no,
# nearest_station=a_survex_station_object, # can be null
nearest_station_description=qm_resolve_station,
nearest_station_name=qm_nearest,
grade=qm_grade.upper(),
- location_description=qm_notes)
+ location_description=qm_notes,
+ found_by = placeholder,
+ cave = survexblock.survexfile.cave)
qm.save
# message = " ! QM{} '{}' CREATED in DB in '{}'".format(qm_no, qm_nearest,survexblock.survexfile.path)
# print(insp+message)