From d1c5f802eeb5cd8e67a11c24230595da431bf5f0 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 10 May 2026 18:00:39 +0100 Subject: [PATCH] nearly there, created auto file --- core/views/new_hole.py | 54 ++++++++++++++++++++++++++++++++++------- templates/new_hole.html | 4 +-- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/core/views/new_hole.py b/core/views/new_hole.py index 6dfbef385..72143477a 100644 --- a/core/views/new_hole.py +++ b/core/views/new_hole.py @@ -2,6 +2,7 @@ import re from django import forms from django.core.exceptions import ValidationError from django.utils.safestring import mark_safe +from django.conf import settings from troggle.parsers.people import who_is_this from core.position_utils import which_area # file-type import, not module type. @@ -29,7 +30,7 @@ class NewHoleForm(forms.Form): surface_wallet = forms.CharField(label="Old wallet used to find the entrance (if any)", widget=forms.TextInput(attrs={'placeholder': 'e.g. 2005 # 63'}), max_length=100, required=False) - survey_wallet = forms.CharField(label="New Wallet for all this data (must match date of trip)", + survey_wallet = forms.CharField(label="New Wallet for all this data (must match the year of the trip)", widget=forms.TextInput(attrs={'placeholder': 'e.g. 2029 # 88'}), required=True) @@ -292,23 +293,58 @@ from django.shortcuts import render, redirect from django.contrib import messages def new_hole(request): - areacode = None + areatext = None if request.method == 'POST': form = NewHoleForm(request.POST, request.FILES) lat = float(form.data['gps_lat']) long = float(form.data['gps_long']) valid, area = which_area(lat, long) if valid: - areacode = f"in {area}" + areatext = f"in {area}" else: - areacode = "Not in 1623 or 1626" + areatext = "Not in 1623 or 1626" if form.is_valid(): - # Data processing to models and filesystem will go here - messages.success(request, "New cave data successfully received.") - return redirect('new_hole') - return redirect('some_success_url') + process_new_hole(form, area) + messages.success(request, "New prospect save data successfully saved.") + + success_url = "/walletedit/" + form.cleaned_data.get('survey_wallet').replace("#",":") + return redirect(success_url) else: form = NewHoleForm() - return render(request, 'new_hole.html', {'form': form, "areacode": areacode}) \ No newline at end of file + return render(request, 'new_hole.html', {'form': form, "areatext": areatext}) + +def get_auto_file(): + auto_gps_file = settings.SURVEX_DATA / "fixedpts/gps/auto.svx" + if not auto_gps_file.exists(): + auto_gps_file.parent.mkdir(parents=True, exist_ok=True) + with open(auto_gps_file, "w") as auto: + auto.write("""; Auto-created GPS fixes from 2026 for new caves in BOTH 1623 and 1626 + *begin + *cs out UTM33 + *cs LONG-LAT + """) + return auto_gps_file + +def process_new_hole(form, area): + """ + + Create a fixed point record by appending to :loser:/fixedpts/gps/auto.svx + Create a new Cave record with associated new Entrance record + Do a git commit (expoweb) of the new Cave and Entrance description files + Do a git commit (loser) of the new GPS position + (git commits use your logged-in identity in the "Who are you ?" field) + Update the database with this new information + + + """ + auto_gps_file = get_auto_file() + fix_line = f"*fix {area}.g{form.cleaned_data.get("cave_id")} {form.cleaned_data.get("gps_lat")} {form.cleaned_data.get("gps_long")} 0.0" + print(fix_line) + with open(auto_gps_file, "w") as auto: + auto.write(fix_line) + auto.write(f"*entrance {area}.g{form.cleaned_data.get("cave_id")}") + + + return \ No newline at end of file diff --git a/templates/new_hole.html b/templates/new_hole.html index 00947849b..53df2a1db 100644 --- a/templates/new_hole.html +++ b/templates/new_hole.html @@ -102,7 +102,7 @@
{{ field.label_tag }} {{ field }} E - {%if areacode %}     {{areacode}}{% endif %} + {%if areatext %}     {{areatext}}{% endif %} {{ field.errors }}
{# Standard Checkbox rendering #} @@ -140,7 +140,7 @@
  • Do a git commit (loser) of the new GPS position
    (git commits use your logged-in identity in the "Who are you ?" field)
  • Update the database with this new information -
  • Create a new Wallet for this information and this trip (if it does not exist) +
  • Take you to a new Wallet for this information and this trip (if it does not exist)
  • Return you to this form if any important data is missing or invalid
  • If all is correct, will take you to the (new) Wallet for you to upload the photos