forked from expo/troggle
nearly there, created auto file
This commit is contained in:
+45
-9
@@ -2,6 +2,7 @@ import re
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from troggle.parsers.people import who_is_this
|
from troggle.parsers.people import who_is_this
|
||||||
from core.position_utils import which_area # file-type import, not module type.
|
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)",
|
surface_wallet = forms.CharField(label="Old wallet used to find the entrance (if any)",
|
||||||
widget=forms.TextInput(attrs={'placeholder': 'e.g. 2005 # 63'}),
|
widget=forms.TextInput(attrs={'placeholder': 'e.g. 2005 # 63'}),
|
||||||
max_length=100, required=False)
|
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'}),
|
widget=forms.TextInput(attrs={'placeholder': 'e.g. 2029 # 88'}),
|
||||||
required=True)
|
required=True)
|
||||||
|
|
||||||
@@ -292,23 +293,58 @@ from django.shortcuts import render, redirect
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
|
||||||
def new_hole(request):
|
def new_hole(request):
|
||||||
areacode = None
|
areatext = None
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = NewHoleForm(request.POST, request.FILES)
|
form = NewHoleForm(request.POST, request.FILES)
|
||||||
lat = float(form.data['gps_lat'])
|
lat = float(form.data['gps_lat'])
|
||||||
long = float(form.data['gps_long'])
|
long = float(form.data['gps_long'])
|
||||||
valid, area = which_area(lat, long)
|
valid, area = which_area(lat, long)
|
||||||
if valid:
|
if valid:
|
||||||
areacode = f"in {area}"
|
areatext = f"in {area}"
|
||||||
else:
|
else:
|
||||||
areacode = "Not in 1623 or 1626"
|
areatext = "Not in 1623 or 1626"
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
# Data processing to models and filesystem will go here
|
process_new_hole(form, area)
|
||||||
messages.success(request, "New cave data successfully received.")
|
messages.success(request, "New prospect save data successfully saved.")
|
||||||
return redirect('new_hole')
|
|
||||||
return redirect('some_success_url')
|
success_url = "/walletedit/" + form.cleaned_data.get('survey_wallet').replace("#",":")
|
||||||
|
return redirect(success_url)
|
||||||
else:
|
else:
|
||||||
form = NewHoleForm()
|
form = NewHoleForm()
|
||||||
|
|
||||||
return render(request, 'new_hole.html', {'form': form, "areacode": areacode})
|
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
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
<div class="field-{{ field.name }}">
|
<div class="field-{{ field.name }}">
|
||||||
{{ field.label_tag }}
|
{{ field.label_tag }}
|
||||||
{{ field }}<span class="unit-label"> E
|
{{ field }}<span class="unit-label"> E
|
||||||
{%if areacode %} <font color="blue"> {{areacode}}</font>{% endif %}</span>
|
{%if areatext %} <font color="blue"> {{areatext}}</font>{% endif %}</span>
|
||||||
{{ field.errors }}
|
{{ field.errors }}
|
||||||
</div>
|
</div>
|
||||||
</div> {# Standard Checkbox rendering #}
|
</div> {# Standard Checkbox rendering #}
|
||||||
@@ -140,7 +140,7 @@
|
|||||||
<li>Do a git commit (loser) of the new GPS position<br />
|
<li>Do a git commit (loser) of the new GPS position<br />
|
||||||
(git commits use your logged-in identity in the "Who are you ?" field)
|
(git commits use your logged-in identity in the "Who are you ?" field)
|
||||||
<li>Update the database with this new information
|
<li>Update the database with this new information
|
||||||
<li>Create a new Wallet for this information and this trip (if it does not exist)
|
<li>Take you to a new Wallet for this information and this trip (if it does not exist)
|
||||||
<li>Return you to this form if any important data is missing or invalid
|
<li>Return you to this form if any important data is missing or invalid
|
||||||
<li>If all is correct, will take you to the (new) Wallet for you to upload the photos
|
<li>If all is correct, will take you to the (new) Wallet for you to upload the photos
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user