2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-05-22 18:56:05 +01:00
This commit is contained in:
2026-05-16 22:48:43 +01:00
parent 7d6f670389
commit e422ffb1bd
3 changed files with 41 additions and 52 deletions
+2 -2
View File
@@ -54,8 +54,8 @@ class SurvexStationLookUpManager(models.Manager):
class SurvexStation(models.Model):
name = models.CharField(max_length=100)
# block = models.ForeignKey("SurvexBlock", null=True, on_delete=models.SET_NULL)
# block not used since 2020. survex stations objects are only used for entrance locations and all taken from the .3d file
# survex stations objects are only used for entrance locations
# and *fix and all taken from the .3d file
objects = SurvexStationLookUpManager() # overwrites SurvexStation.objects and enables lookup()
x = models.FloatField(blank=True, null=True)
y = models.FloatField(blank=True, null=True)
+38 -49
View File
@@ -469,7 +469,23 @@ def insert_before(insert, before, content_list):
return content_list
def clean_write_and_commit(filetuple, comment, editor):
filepath, content, _ = filetuple
print(filepath, comment)
try:
write_and_commit([filetuple], comment, editor) # note [list]
except PermissionError:
message = f"CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {filepath}. Ask a nerd to fix this."
return render(request, "errors/generic.html", {"message": message})
except WriteAndCommitError as e:
message = f"CANNOT git on server for this file {filepath}.\n{e}\nEdits may not be committed.\nAsk a nerd to fix this."
return render(request, "errors/generic.html", {"message": e.message})
except subprocess.SubprocessError as e:
message = f"CANNOT update server for this file {filepath}.\n{e}\nEdits may not be committed.\nAsk a nerd to fix this."
return render(request, "errors/generic.html", {"message": message})
except:
raise
return
def process_new_hole(form, area):
"""
@@ -500,6 +516,11 @@ def process_new_hole(form, area):
writes:
⚡*fix 1623.g2025-bz-06 47.6964481 13.816103 0 # time & date of fix.
we do not put "reference" in the *fix because we know it is used in the Entrance we are creating
NB "warning: Reentering an existing survey is deprecated" [since 2000]
and Olly says he would make this an error if it gets in the way of a new feature or whatever.
so we should produce two auto files, one in the 1623 folder and one in the 1626 folder
"""
@@ -511,13 +532,21 @@ def process_new_hole(form, area):
_newfix(form, area, editor, cave_id, fix_id_basic)
# ⚡ tidy this
cave = _makecave(form, area)
_newent(form, area, editor, f"{area}.{fix_id}", cave) # yes, make the Entrance first
_newent(form, area, editor, fix_id, cave)
_savecave(form, area, editor, cave)
# register the new GPS station in the database
# cf parsers/locations.py: LoadPositions()
# cf models/survex.py class SurvexStation
# (also needed after edit_entrance)
# SurvexStation objects are x/y/x in UTM and have a function to return lat/long which is a bit silly for many uses
# _new_location(fix_id)
_newwallet(form, area, editor)
return
def _newfix(form, area, editor, cave_id, fix_id_basic):
"""Constructs and does the edits to the auto GPS file in the loser repo
"""
auto_gps_file, content_list = get_auto_file()
fix_header = f"; {form.cleaned_data.get("discovery_date")} cave: {cave_id} wallet: {form.cleaned_data.get("survey_wallet")} \n"
@@ -534,20 +563,9 @@ def _newfix(form, area, editor, cave_id, fix_id_basic):
insert_before(insert, f"*end {area}", content_list)
content = "".join(content_list)
file_as_list = [(auto_gps_file, content, "utf8")]
try:
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})
except WriteAndCommitError as e:
message = f"CANNOT git on server for this file {auto_gps_file}.\n{e}\nEdits may not be committed.\nAsk a nerd to fix this."
return render(request, "errors/generic.html", {"message": e.message})
except subprocess.SubprocessError as e:
message = f"CANNOT update server for this file {auto_gps_file}.\n{e}\nEdits may not be committed.\nAsk a nerd to fix this."
return render(request, "errors/generic.html", {"message": message})
except:
raise
filetuple = (auto_gps_file, content, "utf8")
comment = f"Online *fix {area}.{fix_id_basic} "
clean_write_and_commit(filetuple, comment, editor)
return
def _newent(form, areacode, editor, fix_id, cave):
@@ -593,26 +611,12 @@ def _newent(form, areacode, editor, fix_id, cave):
ce =CaveAndEntrance.objects.create(
cave=cave, entranceletter="", entrance=ent
)
#
# Add in saving Entrance to database and then .html file to filesystem and git
#
ent.save() # saves into db
try:
ent_file = ent.file_output()
write_and_commit([ent_file], f"Creating new Entrance {ent}", editor)
# leave other exceptions unhandled so that they bubble up to user interface
except PermissionError:
message = f"CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {ent.filename}. Ask a nerd to fix this."
return render(request, "errors/generic.html", {"message": message})
except WriteAndCommitError as e:
message = f"CANNOT git on server for this file {ent.filename}.\n{e}\nEdits may not be committed.\nAsk a nerd to fix this."
return render(request, "errors/generic.html", {"message": e.message})
except subprocess.SubprocessError as e:
message = f"CANNOT update server for this file {ent.filename}.\n{e}\nEdits may not be committed.\nAsk a nerd to fix this."
return render(request, "errors/generic.html", {"message": message})
except:
raise
ent_file = ent.file_output()
clean_write_and_commit(ent_file, f"Creating new Entrance {ent}", editor)
return
def _guess_survex_file(areacode, id):
@@ -661,23 +665,8 @@ def _makecave(form, areacode):
def _savecave(form, areacode, editor, cave):
cave.save()
try:
cave_file = cave.file_output()
write_and_commit([cave_file], f"Creating new cave {cave}", editor)
# leave other exceptions unhandled so that they bubble up to user interface
except PermissionError:
message = f"CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {cave.filename}. Ask a nerd to fix this."
return render(request, "errors/generic.html", {"message": message})
except WriteAndCommitError as e:
message = f"CANNOT git on server for this file {cave.filename}.\n{e}\nEdits may not be committed.\nAsk a nerd to fix this."
return render(request, "errors/generic.html", {"message": e.message})
except subprocess.SubprocessError as e:
message = f"CANNOT update server for this file {cave.filename}.\n{e}\nEdits may not be committed.\nAsk a nerd to fix this."
return render(request, "errors/generic.html", {"message": message})
except:
raise
cave_file = cave.file_output()
clean_write_and_commit(cave_file, f"Creating new cave {cave}", editor)
return
def _newwallet(form, areacode, editor):
+1 -1
View File
@@ -27,7 +27,7 @@ though, you do not need to do a data import as it happens automatically -->
<lastvisit>{{ entrance.lastvisit|default_if_none:""|safe }}</lastvisit>
<approach>{{ entrance.approach|default_if_none:""|safe }}</approach>
<underground_description>{{ entrance.underground_description|default_if_none:""|safe }}</underground_description>
<photo>{{ entrance.photo|default_if_none:"<img src='/1623/others/t/82jont.jpg' />"|safe }}</photo>
<photo>{{ entrance.photo|safe }}</photo>
<!-- marking options: P = Paint,
P? = Paint (?),
T = Tag,