mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-05-22 18:56:05 +01:00
Does area.fix with *export properly
This commit is contained in:
+86
-21
@@ -36,7 +36,7 @@ class NewHoleForm(forms.Form):
|
||||
widget=forms.TextInput(attrs={'placeholder':
|
||||
'e.g. 2035-ZB-03 '}),
|
||||
max_length=50, required=True)
|
||||
tag_text = forms.CharField(label="Exact text on tag if placed, or seen in-place",
|
||||
tag_text = forms.CharField(label="Exact text on tag if placed (leave blank if none)",
|
||||
widget=forms.TextInput(attrs={'placeholder': 'e.g. 29 CUCC 35'}),
|
||||
max_length=50, required=False)
|
||||
# Naming
|
||||
@@ -412,22 +412,64 @@ 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)
|
||||
print("Writing new auto GPS file")
|
||||
with open(auto_gps_file, "w") as auto:
|
||||
auto.write(dedent(""" ; Auto-created GPS fixes from 2026 for new caves in BOTH 1623 and 1626
|
||||
auto.write(dedent(""" ; Auto-created GPS fixes for new caves (since 2026)
|
||||
; For new caves in BOTH 1623 and 1626
|
||||
|
||||
*begin
|
||||
*cs out UTM33
|
||||
*cs LONG-LAT
|
||||
|
||||
*begin 1623
|
||||
*end 1623
|
||||
|
||||
*begin 1626
|
||||
*end 1626
|
||||
|
||||
*end
|
||||
"""))
|
||||
|
||||
with open(auto_gps_file, "r") as auto:
|
||||
old_content = auto.readlines()
|
||||
|
||||
content_list = [line for line in old_content if "*end" not in line]
|
||||
content = "".join(content_list)
|
||||
print(content)
|
||||
return auto_gps_file, content
|
||||
content_list = [line for line in old_content]
|
||||
return auto_gps_file, content_list
|
||||
|
||||
def insert_before(insert, before, content_list):
|
||||
"""
|
||||
Finds the first occurrence of a target string 'before' in 'content_list'
|
||||
and inserts a list of strings 'insert' right before it.
|
||||
|
||||
Modifies content_list in-place.
|
||||
"""
|
||||
if not before:
|
||||
return
|
||||
if isinstance(insert, str):
|
||||
insert = [insert]
|
||||
|
||||
target_index = None
|
||||
target_clean = before.strip().lower()
|
||||
|
||||
# 1. Find the index of the target line
|
||||
for idx, line in enumerate(content_list):
|
||||
if line.strip().lower() == target_clean:
|
||||
target_index = idx
|
||||
break
|
||||
|
||||
# 2. Insert the new lines if the target was found
|
||||
if target_index is not None:
|
||||
# We loop backwards or use slice assignment to preserve
|
||||
# the order of strings inside the 'insert' list.
|
||||
content_list[target_index:target_index] = insert
|
||||
else:
|
||||
# Optional fallback: if the line isn't found, append to the end
|
||||
# or log a warning depending on your needs.
|
||||
print(f"Error: Could not find target line containing '{before}'")
|
||||
|
||||
return content_list
|
||||
|
||||
|
||||
|
||||
def process_new_hole(form, area):
|
||||
"""
|
||||
@@ -462,30 +504,39 @@ def process_new_hole(form, area):
|
||||
|
||||
|
||||
editor = git_string(form.cleaned_data["who_are_you"])
|
||||
fix_id = f"{area}.g{form.cleaned_data.get("cave_id").lower()}"
|
||||
fix_id_basic = f"g{form.cleaned_data.get("cave_id").lower()}"
|
||||
fix_id = f"{area}.{fix_id_basic}"
|
||||
|
||||
_newfix(form, area, editor, fix_id)
|
||||
cave_id = form.cleaned_data.get("cave_id").upper()
|
||||
_newfix(form, area, editor, cave_id, fix_id_basic)
|
||||
# ⚡ tidy this
|
||||
cave = _makecave(form, area)
|
||||
_newent(form, area, editor, fix_id, cave) # yes, make the Entrance first
|
||||
_newent(form, area, editor, f"{area}.{fix_id}", cave) # yes, make the Entrance first
|
||||
_savecave(form, area, editor, cave)
|
||||
|
||||
_newwallet(form, area, editor)
|
||||
return
|
||||
|
||||
def _newfix(form, area, editor, fix_id):
|
||||
auto_gps_file, content = get_auto_file()
|
||||
fix_line = f"*fix {fix_id} {form.cleaned_data.get("gps_lat")} {form.cleaned_data.get("gps_long")} 0\n"
|
||||
def _newfix(form, area, editor, cave_id, fix_id_basic):
|
||||
auto_gps_file, content_list = get_auto_file()
|
||||
|
||||
content += f"\n; {form.cleaned_data.get("discovery_date")} wallet: {form.cleaned_data.get("survey_wallet")} \n"
|
||||
content += fix_line
|
||||
content += f"*entrance {fix_id}\n"
|
||||
content +=f"\n*end\n"
|
||||
fix_header = f"; {form.cleaned_data.get("discovery_date")} cave: {cave_id} wallet: {form.cleaned_data.get("survey_wallet")} \n"
|
||||
|
||||
files = [(auto_gps_file, content, "utf8")]
|
||||
fix_line = f"*fix {area}.{fix_id_basic} {form.cleaned_data.get("gps_long")} {form.cleaned_data.get("gps_lat")} 0\n"
|
||||
fix_entrance = f"*entrance {area}.{fix_id_basic}\n\n"
|
||||
|
||||
insert = [fix_header, fix_line, fix_entrance]
|
||||
insert_before(insert, f"*end", content_list)
|
||||
|
||||
fix_export = f"*export {fix_id_basic}\n" # must be immediately after a *begin..
|
||||
|
||||
insert = fix_export
|
||||
insert_before(insert, f"*end {area}", content_list)
|
||||
|
||||
content = "".join(content_list)
|
||||
file_as_list = [(auto_gps_file, content, "utf8")]
|
||||
try:
|
||||
write_and_commit(files, f"Online *fix {fix_id} ", editor)
|
||||
write_and_commit(file_as_list, f"Online *fix {fix_id} ", editor)
|
||||
except PermissionError:
|
||||
message = f"CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {auto_gps_file}. Ask a nerd to fix this."
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
@@ -509,18 +560,32 @@ def _newent(form, areacode, editor, fix_id, cave):
|
||||
|
||||
In the parser, the Entrance is created first, then the Cave. But when doing NewCave, the Cave is created
|
||||
first, then the Entrance. So this code is derived from a bit of both.
|
||||
|
||||
marking options: P = Paint,
|
||||
P? = Paint (?),
|
||||
T = Tag,
|
||||
T? = Tag (?),
|
||||
R = Retagged,
|
||||
S = Spit,
|
||||
S? = Spit (?),
|
||||
U = Unmarked,
|
||||
? = Unknown"
|
||||
"""
|
||||
slug = f"{areacode}-{form.cleaned_data.get("cave_id")}" # no letter suffix a,b, or c..
|
||||
imgpath = Path(areacode) / form.cleaned_data.get("cave_id")
|
||||
|
||||
|
||||
if form.cleaned_data.get("tag_text"):
|
||||
marking = "T" # tag
|
||||
else:
|
||||
marking="U" # Unmarked
|
||||
ent = Entrance.objects.create( # creates object
|
||||
slug=slug,
|
||||
filename = slug + ".html",
|
||||
findability="S", # Coordinates
|
||||
marking="U", # Unmarked
|
||||
findability="S", # Coordinates, Surveyed
|
||||
marking=marking,
|
||||
approach= form.cleaned_data.get("approach"),
|
||||
entrance_description=form.cleaned_data.get("entrance_description"),
|
||||
# location_description=location_description[0],
|
||||
lastvisit=form.cleaned_data.get("discovery_date"),
|
||||
other_station=fix_id,
|
||||
)
|
||||
|
||||
@@ -82,7 +82,9 @@
|
||||
<h1>New Cave Datasheet</h1>
|
||||
|
||||
<h3>Instructions</h3>
|
||||
<p>Refer to the handbook <a href="">New Cave Datasheet</a> page for what all these mean and how to fill them in.</p>
|
||||
<p>Refer to the handbook <a href="/handbook/l/new-cave-form.html">New Cave Datasheet</a>
|
||||
page for what all these mean and how to fill them in.</p>
|
||||
<p>If starting from scrastch, read <a href="/handbook/survey/newcave.html">New Cave Process</a>.
|
||||
|
||||
<form action="" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
|
||||
Reference in New Issue
Block a user