mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-03-01 03:01:41 +00:00
stop print msgs many more
This commit is contained in:
@@ -36,7 +36,7 @@ def fix(request, areacode="1626"):
|
||||
caves_in_area = list(Cave.objects.filter(areacode=areacode, kataster_number=""))
|
||||
caves_nodir=[]
|
||||
ents = []
|
||||
print(f"\n---------- {areacode}")
|
||||
# print(f"\n---------- {areacode}")
|
||||
|
||||
# hack because some caves in 1623 have already been katastered. Bugger. That screws things up.
|
||||
for i in range(303,316):
|
||||
@@ -70,12 +70,12 @@ def fix(request, areacode="1626"):
|
||||
for e in ce:
|
||||
# print(" ",e.entrance.slug, e.entrance.filename)
|
||||
e_html = ents_html / e.entrance.filename
|
||||
print(range(303,316), cc.kataster_number)
|
||||
# print(range(303,316), cc.kataster_number)
|
||||
if cc.kataster_number and int(cc.kataster_number) in range(303,316):
|
||||
original_number = cc.kataster_number
|
||||
u = cc.unofficial_number
|
||||
k = cc.kataster_number
|
||||
print(u,k)
|
||||
# print(u,k)
|
||||
e_html = ents_html / e_html.name.replace(f"{cc.unofficial_number}",f"{cc.kataster_number}")
|
||||
if not e_html.is_file():
|
||||
e_html = ents_html / e_html.name.replace(f"{original_number}",f"{cc.kataster_number}")
|
||||
@@ -86,7 +86,7 @@ def fix(request, areacode="1626"):
|
||||
for line in f:
|
||||
search_term = f"{areacode}" + "/(l|t|i)/([^'\"]*)"
|
||||
if match := re.findall(search_term, line):
|
||||
print(c, search_term, match, line)
|
||||
# print(c, search_term, match, line)
|
||||
for m in match:
|
||||
dir, filename = m
|
||||
to_move.append(("e", dir, original_number, e.entrance.filename, filename))
|
||||
@@ -106,12 +106,12 @@ def fix(request, areacode="1626"):
|
||||
# caves_nodir.append(c.unofficial_number)
|
||||
|
||||
for key, dir, cave_id, filename, target in to_move:
|
||||
if key == "c":
|
||||
print((key, dir, cave_id, filename, target))
|
||||
print("")
|
||||
# if key == "c":
|
||||
# print((key, dir, cave_id, filename, target))
|
||||
# print("")
|
||||
for key, dir, cave_id, filename, target in to_move:
|
||||
if key == "e":
|
||||
print((key, dir, cave_id, filename, target))
|
||||
# if key == "e":
|
||||
# print((key, dir, cave_id, filename, target))
|
||||
|
||||
newdirs = set()
|
||||
for key, dir, cave_id, filename, target in to_move:
|
||||
@@ -240,7 +240,7 @@ def kataster(request, slug=None):
|
||||
entrance_data = []
|
||||
for ent in ent_dir.iterdir():
|
||||
if str(ent.name).startswith(str(cave)):
|
||||
print(ent.name)
|
||||
# print(ent.name)
|
||||
entrance_data.append("entrance_data/"+ent.name)
|
||||
|
||||
mvscript += f'sed -i "/<slug>{str(cave)}/d" {ent.name}\n'
|
||||
@@ -276,9 +276,9 @@ def kataster(request, slug=None):
|
||||
except:
|
||||
return mvscript
|
||||
if (loser_dir).is_dir():
|
||||
print(loser_dir)
|
||||
# print(loser_dir)
|
||||
for svx in loser_dir.iterdir():
|
||||
print(svx)
|
||||
# print(svx)
|
||||
loser_data.append(Path(loser_dir , svx).name)
|
||||
return mvscript
|
||||
|
||||
@@ -298,7 +298,7 @@ def kataster(request, slug=None):
|
||||
l_script += f'sed -i "/^*end/s/{survex_name}/{knum}/" {loser_name}/{survex_name}.svx\n'
|
||||
l_script +=f"# These 'sed' edits will not do everything in all cases, but they do the basics\n\n"
|
||||
except FileNotFoundError as e:
|
||||
print(e)
|
||||
# print(e)
|
||||
loser_name = ""
|
||||
l_script = f"\n# {e}\n\n"
|
||||
|
||||
@@ -347,15 +347,15 @@ def kataster(request, slug=None):
|
||||
for line in f:
|
||||
if match := re.search(r'<entranceslug>(.*?)</entranceslug>', line):
|
||||
entrance = match.group(1)
|
||||
print(entrance)
|
||||
# print(entrance)
|
||||
|
||||
except PermissionError as e:
|
||||
msg=f"CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {cavefilename}. Ask a nerd to fix this: {e}"
|
||||
print(msg)
|
||||
# print(msg)
|
||||
raise
|
||||
except Exception as e:
|
||||
msg=f"CANNOT write this file {cavefilename}. Ask a nerd to fix this: {e}"
|
||||
print(msg)
|
||||
# print(msg)
|
||||
|
||||
# Restart script with POST data
|
||||
script = "# Conversion script - nearly complete\n# When doing it by hand, it is less error-prone to do the file re-namings last,\n"
|
||||
@@ -371,7 +371,7 @@ def kataster(request, slug=None):
|
||||
if form.is_valid():
|
||||
clean = form.cleaned_data
|
||||
knum = clean['kataster_number']
|
||||
print(f" # kataster_number {clean['kataster_number']}")
|
||||
# print(f" # kataster_number {clean['kataster_number']}")
|
||||
if test := get_cave_from_slug(f"{cave.areacode}-{knum}"):
|
||||
warning = "<br /><br />DANGER DANGER You will overwrite an existing katastered cave !!!<br />"
|
||||
warning += "resetting proposed new kataster number to 666.<br /><br />"
|
||||
|
||||
@@ -66,7 +66,7 @@ def dwgfilesingle(request, path):
|
||||
try:
|
||||
# print(f'attempting {encoding} for {tfile}')
|
||||
with open(tfile, encoding=encoding, errors="strict") as f:
|
||||
print(f"- before reading any {encoding}")
|
||||
# print(f"- before reading any {encoding}")
|
||||
lines = f.readlines()
|
||||
# print(f'- finished reading {encoding}')
|
||||
clean = []
|
||||
@@ -81,10 +81,10 @@ def dwgfilesingle(request, path):
|
||||
)
|
||||
|
||||
except:
|
||||
print(f"! Exception when reading {encoding}")
|
||||
# print(f"! Exception when reading {encoding}")
|
||||
continue
|
||||
|
||||
print(f"! None of those encodings worked for {tfile}")
|
||||
# print(f"! None of those encodings worked for {tfile}")
|
||||
try:
|
||||
return HttpResponse(content=open(tfile, errors="ignore"), content_type=getmimetype(tfile))
|
||||
except:
|
||||
|
||||
@@ -47,15 +47,15 @@ and the git "--author" field which is used (only) for the version control attrib
|
||||
def create_new_lbe_slug(date):
|
||||
onthisdate = LogbookEntry.objects.filter(date=date)
|
||||
n = len(onthisdate)
|
||||
print(f" Already entries on this date: {n}\n {onthisdate}")
|
||||
# print(f" Already entries on this date: {n}\n {onthisdate}")
|
||||
|
||||
suffix = alphabet_suffix(n+1)
|
||||
|
||||
tid = f"{date}{suffix}"
|
||||
if len(tid) <=4 :
|
||||
print(f"BAD ERROR {tid=}")
|
||||
# print(f"BAD ERROR {tid=}")
|
||||
tid = f"{date}_{LogbookEntry.objects.count()}_{n}" # fudged number
|
||||
print(f"{tid=}")
|
||||
# print(f"{tid=}")
|
||||
return tid
|
||||
|
||||
def store_edited_entry_into_database(date, place, title, text, others, author, tu, slug):
|
||||
@@ -104,19 +104,19 @@ def store_edited_entry_into_database(date, place, title, text, others, author, t
|
||||
if len(name) > 0:
|
||||
if name[0] == "*": # a name prefix of "*" is special, just a string.
|
||||
odds.append(name)
|
||||
print(f" - adding * special name '{name}'")
|
||||
# print(f" - adding * special name '{name}'")
|
||||
else:
|
||||
try:
|
||||
personyear = GetPersonExpeditionNameLookup(expedition).get(name.lower())
|
||||
if not personyear:
|
||||
odds.append(name)
|
||||
print(f" - adding unrecognised expoer '{name}'")
|
||||
# print(f" - adding unrecognised expoer '{name}'")
|
||||
if known_foreigner(name):
|
||||
message = f" ! - Known foreigner: '{name}' in entry {slug=}"
|
||||
print(message)
|
||||
# print(message)
|
||||
else:
|
||||
message = f" ! - No name match for: '{name}' in entry {slug=}"
|
||||
print(message)
|
||||
# print(message)
|
||||
DataIssue.objects.create(parser="logbooks", message=message)
|
||||
else:
|
||||
coUniqueAttribs = {"personexpedition": personyear, "nickname_used": name, "logbook_entry": lbo} # lbo is primary key
|
||||
@@ -126,14 +126,14 @@ def store_edited_entry_into_database(date, place, title, text, others, author, t
|
||||
except:
|
||||
# This should not happen. We do not raise exceptions in that function
|
||||
message = f" ! - EXCEPTION: '{name}' in entry {slug=}"
|
||||
print(message)
|
||||
# print(message)
|
||||
DataIssue.objects.create(parser="logbooks", message=message)
|
||||
raise
|
||||
|
||||
PersonLogEntry.objects.bulk_create(pt_list)
|
||||
|
||||
lbo.other_people = ", ".join(odds)
|
||||
print(f" - Saving other_people '{lbo.other_people}'")
|
||||
# print(f" - Saving other_people '{lbo.other_people}'")
|
||||
lbo.save()
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ def logbookedit(request, year=None, slug=None):
|
||||
form = LogbookEditForm(request.POST)
|
||||
if not form.is_valid():
|
||||
message = f'Invalid form response for logbook entry creating "{request.POST}"'
|
||||
print(message)
|
||||
# print(message)
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
else:
|
||||
editor = form.cleaned_data["who_are_you"]
|
||||
@@ -238,16 +238,16 @@ def logbookedit(request, year=None, slug=None):
|
||||
|
||||
try:
|
||||
odate = datetime.strptime(date.replace(".", "-"), "%Y-%m-%d").date()
|
||||
print(f"{odate.year=}")
|
||||
# print(f"{odate.year=}")
|
||||
if str(odate.year) == year:
|
||||
dateflag = False
|
||||
else:
|
||||
print(f"Trying to change the year ! No!! {odate.year=}")
|
||||
# print(f"Trying to change the year ! No!! {odate.year=}")
|
||||
odate = datetime.strptime(f"{year}-01-01", "%Y-%m-%d").date()
|
||||
dateflag = True
|
||||
except:
|
||||
odate = datetime.strptime(f"{year}-01-01", "%Y-%m-%d").date()
|
||||
print(f"! Invalid date string {date}, setting to {odate}")
|
||||
# print(f"! Invalid date string {date}, setting to {odate}")
|
||||
dateflag = True
|
||||
date = odate.isoformat()
|
||||
|
||||
@@ -258,7 +258,7 @@ def logbookedit(request, year=None, slug=None):
|
||||
authorflag = False
|
||||
else:
|
||||
authorflag = True
|
||||
print(f"! Unrecognised author: {author}")
|
||||
# print(f"! Unrecognised author: {author}")
|
||||
|
||||
# if somehow we get a slug set to just '2024', not eg '2020-08-10b'
|
||||
# because the URL of the page is /logbookedit/2022 for a new entry
|
||||
@@ -282,10 +282,10 @@ def logbookedit(request, year=None, slug=None):
|
||||
# OK we could patch the object in place, but if the people on the trip have changed this
|
||||
# would get very messy. So we delete it, and thus all the dependent objects,
|
||||
# and recreate it and all its links. It might not exist though.
|
||||
print(f"- Deleting the LogBookEntry {slug}")
|
||||
# print(f"- Deleting the LogBookEntry {slug}")
|
||||
LogbookEntry.objects.filter(slug=slug).delete() # works even if it does not exist
|
||||
|
||||
print(f"- Creating the LogBookEntry {slug}")
|
||||
# print(f"- Creating the LogBookEntry {slug}")
|
||||
year = slug[0:4]
|
||||
try:
|
||||
expedition = Expedition.objects.get(year=year)
|
||||
@@ -298,26 +298,26 @@ def logbookedit(request, year=None, slug=None):
|
||||
1. Press the Back button on your broswer to return to the screen where you typed up the entry,
|
||||
2. Copy the text of what you wrote into a new text file,
|
||||
3. Direct a nerd to fix this. It should take only a couple of minutes.'''
|
||||
print(message)
|
||||
# print(message)
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
store_edited_entry_into_database(date, place, title, entry, others, author, tu, slug)
|
||||
|
||||
# Successful POST so save to fiesystem
|
||||
json_entries_dir = settings.EXPOWEB / "years" / year / settings.JSON_LOG_ENTRIES
|
||||
if json_entries_dir.is_dir(): # only 2025 currently, or the current expo
|
||||
print(f"- Rewriting JUST this edited logbook entry to a JSON file. ")
|
||||
# print(f"- Rewriting JUST this edited logbook entry to a JSON file. ")
|
||||
this_entry = LogbookEntry.objects.get(slug=slug)
|
||||
|
||||
write_entries_json([this_entry], year, editor)
|
||||
else:
|
||||
print(f"- Rewriting the entire {year} logbook to disc ")
|
||||
# print(f"- Rewriting the entire {year} logbook to disc ")
|
||||
filename= "logbook.html"
|
||||
try:
|
||||
print(f" - Logbook for {year} to be exported and written out.")
|
||||
# print(f" - Logbook for {year} to be exported and written out.")
|
||||
writelogbook(year, filename) # uses a template, not the code fragment below which is just a visible hint to logged on user
|
||||
except:
|
||||
message = f'! - Logbook saving failed - \n!! Permissions failure ?! on attempting to save file "logbook.html"'
|
||||
print(message)
|
||||
# print(message)
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
|
||||
|
||||
@@ -401,7 +401,7 @@ def logbookedit(request, year=None, slug=None):
|
||||
return render(request, "object_list.html", {"object_list": lbes}) # ie a bug
|
||||
else:
|
||||
lbe = lbes[0]
|
||||
print(f"{lbe}")
|
||||
# print(f"{lbe}")
|
||||
tu = clean_tu(lbe.time_underground)
|
||||
|
||||
people = []
|
||||
|
||||
@@ -37,7 +37,7 @@ def notablepersons(request):
|
||||
def notabilitykey(person):
|
||||
return person.notability()
|
||||
|
||||
print(request)
|
||||
# print(request)
|
||||
persons = Person.objects.order_by('fullname')
|
||||
# From what I can tell, "persons" seems to be the table rows, while "pcols" is the table columns. - AC 16 Feb 09
|
||||
pcols = []
|
||||
@@ -241,7 +241,7 @@ def personexpedition(request, slug="", year=""):
|
||||
)
|
||||
except:
|
||||
msg = f" Person '{slug=}' or year '{year=}' not found in database. Please report this to a nerd."
|
||||
print(msg)
|
||||
# print(msg)
|
||||
return render(request, "errors/generic.html", {"message": msg})
|
||||
|
||||
def logentrydelete(request, year):
|
||||
@@ -250,22 +250,22 @@ def logentrydelete(request, year):
|
||||
This function is dedicated to James Waite who managed to make so many duplicate logbook entries
|
||||
that we needed a special mechanism to delete them.
|
||||
"""
|
||||
for i in request.POST:
|
||||
print(f" - '{i}' {request.POST[i]}")
|
||||
# for i in request.POST:
|
||||
# print(f" - '{i}' {request.POST[i]}")
|
||||
eslug = request.POST["entry_slug"]
|
||||
entry = LogbookEntry.objects.get(slug=eslug)
|
||||
# OK we delete it from the db and then re-save logbook.html file
|
||||
# to ensure that the permanent record also has the entry deleted.
|
||||
entry.delete()
|
||||
|
||||
print(f"- Rewriting the entire {year} logbook to disc ")
|
||||
# print(f"- Rewriting the entire {year} logbook to disc ")
|
||||
filename= "logbook.html"
|
||||
try:
|
||||
writelogbook(year, filename) # uses a template
|
||||
|
||||
except:
|
||||
message = f'! - Logbook saving failed - \n!! Permissions failure ?! on attempting to save file "logbook.html"'
|
||||
print(message)
|
||||
# print(message)
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ def get_entries(year):
|
||||
entry.who.append(p)
|
||||
except Exception as e:
|
||||
msg = f' Logbook report for year:"{year}" not implemented yet\n{e}\n {context}'
|
||||
print(msg)
|
||||
# print(msg)
|
||||
return render(request, "errors/generic.html", {"message": msg})
|
||||
return dateditems
|
||||
|
||||
@@ -342,7 +342,7 @@ def logbookentry(request, date, slug):
|
||||
trips = LogbookEntry.objects.filter(date=date) # all the trips not just this one
|
||||
except ValidationError:
|
||||
msg = f' Logbook entry invalid date:"{date}" probably because of relative (not absolute) addressing of "src=" or "haref=" in the text'
|
||||
print(msg)
|
||||
# print(msg)
|
||||
return render(request, "errors/generic.html", {"message": msg})
|
||||
this_logbookentry = trips.filter(date=date, slug=slug)
|
||||
year = slug[:4]
|
||||
@@ -367,7 +367,7 @@ def logbookentry(request, date, slug):
|
||||
)
|
||||
else:
|
||||
msg = f' Logbook entry slug:"{slug}" not found in database on date:"{date}" '
|
||||
print(msg)
|
||||
# print(msg)
|
||||
return render(request, "errors/generic.html", {"message": msg})
|
||||
|
||||
@login_required_if_public
|
||||
@@ -387,14 +387,14 @@ def logbookfile(request, year):
|
||||
# indovidual entry edits for this year
|
||||
contents_path = settings.EXPOWEB / "years" / year / exp.logbookfile
|
||||
try:
|
||||
print(f" - Logbook for {year} to be exported and written out.")
|
||||
# print(f" - Logbook for {year} to be exported and written out.")
|
||||
writelogbook(year, exp.logbookfile, generate_on_view=True) # uses a template
|
||||
commit_msg = f"Request to see whole logbook triggers re-exporting."
|
||||
editor = get_editor(request)
|
||||
add_commit(contents_path, commit_msg, editor)
|
||||
except:
|
||||
message = f'! - Logbook saving to file from database failed - \n!! Permissions failure ?! on attempting to save file {contents_path}'
|
||||
print(message)
|
||||
# print(message)
|
||||
raise # got a one-off failure here, we need to know why..
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
|
||||
@@ -439,7 +439,7 @@ def write_entries_json(entries, year, editor):
|
||||
f"CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {filepath}. Ask a nerd to fix this: {e}"
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"CANNOT write this file {filepath}. Exception dumping json. Ask a nerd to fix this: {e}")
|
||||
# print(f"CANNOT write this file {filepath}. Exception dumping json. Ask a nerd to fix this: {e}")
|
||||
raise e
|
||||
|
||||
def serialize_logentry(le):
|
||||
@@ -486,7 +486,7 @@ def write_entries_json(entries, year, editor):
|
||||
|
||||
for le in entries:
|
||||
# filename = f"{le.slug}-{le.pk:03}.json"
|
||||
print(le)
|
||||
# print(le)
|
||||
filename = f"{le.slug}.json"
|
||||
filepath = dirpath / filename
|
||||
ensure_dir_exists(filepath)
|
||||
|
||||
@@ -520,43 +520,43 @@ def gpxupload(request, folder=None):
|
||||
urldir = f"/gpxupload/{year}"
|
||||
|
||||
ctx.update({"folder": folder_arg, "dirpath": dirpath, "urlfile": urlfile, "urldir": urldir})
|
||||
print(f"gpxupload() {_setup.__name__} -> {folder_arg=} {dirpath=} {urlfile=} {urldir=}")
|
||||
# print(f"gpxupload() {_setup.__name__} -> {folder_arg=} {dirpath=} {urlfile=} {urldir=}")
|
||||
return ctx
|
||||
|
||||
def _post(ctx):
|
||||
print(f"gpxupload() method=POST")
|
||||
for i in request.POST:
|
||||
print(" ", i)
|
||||
# print(f"gpxupload() method=POST")
|
||||
# for i in request.POST:
|
||||
# print(" ", i)
|
||||
|
||||
formd = GPXuploadForm(request.POST)
|
||||
ctx["formd"] = formd
|
||||
|
||||
# prospector creation branch (preserve original behavior and prints)
|
||||
if "prospector" in request.POST:
|
||||
print(f"gpxupload() {request.POST=}\n {request.POST.get('prospector')=}")
|
||||
# print(f"gpxupload() {request.POST=}\n {request.POST.get('prospector')=}")
|
||||
if formd.is_valid():
|
||||
newprospector = sanitize_name(request.POST["prospector"])
|
||||
print(f"gpxupload() {newprospector=}")
|
||||
# print(f"gpxupload() {newprospector=}")
|
||||
try:
|
||||
(ctx["yearpath"] / newprospector).mkdir(parents=True, exist_ok=True)
|
||||
except Exception as e:
|
||||
message = f'\n !! Permissions failure ?! 0 attempting to mkdir "{(ctx["yearpath"] / newprospector)}": {e}'
|
||||
print(message)
|
||||
# print(message)
|
||||
raise
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
return ctx
|
||||
|
||||
# file upload branch
|
||||
print(f"gpxupload() no prospector field")
|
||||
print(f"gpxupload() {request.FILES=}")
|
||||
for i in request.FILES:
|
||||
print(" ", i)
|
||||
# print(f"gpxupload() no prospector field")
|
||||
# print(f"gpxupload() {request.FILES=}")
|
||||
# for i in request.FILES:
|
||||
# print(" ", i)
|
||||
|
||||
print(f"gpxupload() about to look at request.FILES")
|
||||
# print(f"gpxupload() about to look at request.FILES")
|
||||
multiple = request.FILES.getlist("uploadfiles")
|
||||
if not multiple:
|
||||
# user supplied no files — attach a form error and return to show it
|
||||
print(f"gpxupload(): no files to upload {multiple}")
|
||||
# print(f"gpxupload(): no files to upload {multiple}")
|
||||
formd.add_error("uploadfiles", "No files uploaded.") # does not seem to be visible on form?
|
||||
ctx["formd"] = formd
|
||||
return ctx
|
||||
@@ -572,9 +572,9 @@ def gpxupload(request, folder=None):
|
||||
try: # crashes in Django os.chmod call if on WSL, but does save file!
|
||||
saved_filename = fs.save(f.name, content=f)
|
||||
except Exception:
|
||||
print(
|
||||
f'\n !! Permissions failure ?! 3 attempting to save "{f.name}" in "{ctx["dirpath"]}"'
|
||||
)
|
||||
# print(
|
||||
# f'\n !! Permissions failure ?! 3 attempting to save "{f.name}" in "{ctx["dirpath"]}"'
|
||||
# )
|
||||
if "saved_filename" in locals():
|
||||
if (ctx["dirpath"] / saved_filename).is_file():
|
||||
ctx["actual_saved"].append(saved_filename)
|
||||
@@ -584,7 +584,8 @@ def gpxupload(request, folder=None):
|
||||
ctx["actual_saved"].append(saved_filename)
|
||||
ctx["filesaved"] = True
|
||||
else:
|
||||
print(f"gpxupload(): not a GPX file {f.name=}")
|
||||
pass
|
||||
# print(f"gpxupload(): not a GPX file {f.name=}")
|
||||
|
||||
return ctx
|
||||
|
||||
@@ -600,7 +601,8 @@ def gpxupload(request, folder=None):
|
||||
except FileNotFoundError:
|
||||
files.append("(no folder yet - would be created)")
|
||||
except Exception as e:
|
||||
print(f"gpxupload() EXCEPTION\n {e}")
|
||||
pass
|
||||
# print(f"gpxupload() EXCEPTION\n {e}")
|
||||
ctx["files"] = sorted(files) if files else []
|
||||
ctx["dirs"] = sorted(dirs) if dirs else []
|
||||
return ctx
|
||||
@@ -616,11 +618,11 @@ def gpxupload(request, folder=None):
|
||||
else:
|
||||
ctx = _get(ctx)
|
||||
|
||||
print(f"gpxupload() drop through")
|
||||
# print(f"gpxupload() drop through")
|
||||
files = ctx.get("files", [])
|
||||
dirs = ctx.get("dirs", [])
|
||||
|
||||
print(f"gpxupload() about to render..")
|
||||
# print(f"gpxupload() about to render..")
|
||||
return render(
|
||||
request,
|
||||
"gpxuploadform.html",
|
||||
@@ -641,7 +643,8 @@ def gpxupload(request, folder=None):
|
||||
def analyse_gpx(saved_filename, content):
|
||||
"""For an uploaded GPX file, analyse it to get a *fix number
|
||||
"""
|
||||
print(f"analyse_gpx(): {saved_filename} -- {content.name} length: {len(content)} bytes")
|
||||
pass
|
||||
# print(f"analyse_gpx(): {saved_filename} -- {content.name} length: {len(content)} bytes")
|
||||
|
||||
@login_required_if_public
|
||||
def gpxfix(request):
|
||||
@@ -681,7 +684,7 @@ def gpxfix(request):
|
||||
multiple = request.FILES.getlist("uploadfiles")
|
||||
if not multiple:
|
||||
# user supplied no files — attach a form error and return to show it
|
||||
print(f"gpxfix(): no files to upload {multiple}")
|
||||
# print(f"gpxfix(): no files to upload {multiple}")
|
||||
formd.add_error("uploadfiles", "No files uploaded.") # does not seem to be visible on form?
|
||||
ctx["formd"] = formd
|
||||
return ctx
|
||||
@@ -691,14 +694,14 @@ def gpxfix(request):
|
||||
ctx["yearpath"].mkdir(parents=True, exist_ok=True)
|
||||
except Exception as e:
|
||||
message = f'\n !! Permissions failure ?! 0 attempting to mkdir "{ctx["yearpath"]}": {e}'
|
||||
print(message)
|
||||
# print(message)
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
|
||||
# if a prospector field was submitted, validate it
|
||||
if "prospector" in request.POST:
|
||||
if formd.is_valid():
|
||||
newprospector = sanitize_name(request.POST["prospector"])
|
||||
print(f"gpxfix() prospector named: {newprospector}")
|
||||
# print(f"gpxfix() prospector named: {newprospector}")
|
||||
|
||||
ctx["areacode"] = request.POST["areacode"].strip()
|
||||
|
||||
@@ -711,7 +714,7 @@ def gpxfix(request):
|
||||
try:
|
||||
saved_filename = fs.save(f.name, content=f)
|
||||
except Exception as e:
|
||||
print(f'\n !! Permissions failure ?! on attempting to save "{f.name}" in "{ctx["dirpath"]}": {e}')
|
||||
# print(f'\n !! Permissions failure ?! on attempting to save "{f.name}" in "{ctx["dirpath"]}": {e}')
|
||||
# if save partially succeeded, guard against referencing undefined vars
|
||||
continue
|
||||
filepath = ctx["dirpath"] / saved_filename
|
||||
@@ -722,9 +725,11 @@ def gpxfix(request):
|
||||
try:
|
||||
ctx["location_data"].append(analyse_gpx(saved_filename, f))
|
||||
except Exception as e:
|
||||
print(f"gpxfix(): analyse_gpx failed for {saved_filename}: {e}")
|
||||
pass
|
||||
# print(f"gpxfix(): analyse_gpx failed for {saved_filename}: {e}")
|
||||
else:
|
||||
print(f"gpxfix(): not a GPX file {f.name=}")
|
||||
pass
|
||||
# print(f"gpxfix(): not a GPX file {f.name=}")
|
||||
|
||||
ctx["fixstring"] = f"*fix {request.POST["station"]} 13.8229370 47.6874630 1871 # {request.POST["prospector"]}: {multiple[0]}"
|
||||
ctx["entrancestring"] = f"*entrance {request.POST["station"]}"
|
||||
@@ -742,7 +747,8 @@ def gpxfix(request):
|
||||
except FileNotFoundError:
|
||||
files.append("(no folder yet - would be created)")
|
||||
except Exception as e:
|
||||
print(f"gpxfix() EXCEPTION\n {e}")
|
||||
pass
|
||||
# print(f"gpxfix() EXCEPTION\n {e}")
|
||||
ctx["files"] = sorted(files) if files else []
|
||||
ctx["dirs"] = sorted(dirs) if dirs else []
|
||||
return ctx
|
||||
@@ -886,7 +892,7 @@ def dwgupload(request, folder=None, gitdisable="no"):
|
||||
except Exception as e:
|
||||
# save failed: abort with error page
|
||||
message = f'! - FORM dwgupload - Permissions failure saving "{f.name}" in "{savepath}": {e}'
|
||||
print(message)
|
||||
# print(message)
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
|
||||
filepath = ctx["dirpath"] / saved_filename
|
||||
@@ -900,7 +906,7 @@ def dwgupload(request, folder=None, gitdisable="no"):
|
||||
dwgfile.save()
|
||||
else:
|
||||
message = f"! - FORM dwgupload - NOT A FILE {Path(ctx['dirpath'], saved_filename)=}."
|
||||
print(message)
|
||||
# print(message)
|
||||
|
||||
if ctx["actual_saved"]:
|
||||
ctx["filesaved"] = True
|
||||
@@ -914,7 +920,7 @@ def dwgupload(request, folder=None, gitdisable="no"):
|
||||
else:
|
||||
if ctx["refused"]:
|
||||
message = f"! - FORM dwgupload - Nothing actually saved. All were refused. {ctx['actual_saved']=}"
|
||||
print(message)
|
||||
# print(message)
|
||||
|
||||
return ctx
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl):
|
||||
file_complaint = f"{wallet} Incorrect survex file name. File {sx} was not found in LOSER repo"
|
||||
complaints.append(file_complaint)
|
||||
message = f"! {file_complaint}"
|
||||
print(message)
|
||||
# print(message)
|
||||
DataIssue.objects.update_or_create(
|
||||
parser="wallets", message=message, url=wurl
|
||||
) # set URL to this wallet folder
|
||||
@@ -187,8 +187,8 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl):
|
||||
DataIssue.objects.update_or_create(
|
||||
parser="wallets", message=message, url=wurl
|
||||
) # set URL to this wallet folder
|
||||
for s in QSsvxfiles:
|
||||
print(s.path, s.cave, s.primary)
|
||||
# for s in QSsvxfiles:
|
||||
# print(s.path, s.cave, s.primary)
|
||||
# QSsvxfiles[0] # dont' know how this happened, fix later..
|
||||
except:
|
||||
file_complaint = (
|
||||
@@ -197,7 +197,7 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl):
|
||||
)
|
||||
complaints.append(file_complaint)
|
||||
message = f"! {file_complaint}"
|
||||
print(message)
|
||||
# print(message)
|
||||
DataIssue.objects.update_or_create(
|
||||
parser="wallets", message=message, url=wurl
|
||||
) # set URL to this wallet folder
|
||||
@@ -475,11 +475,11 @@ def walletedit(request, path=None):
|
||||
waldata = json.load(json_file)
|
||||
except:
|
||||
message = f"! {wallet} Failed to load {contents_path} JSON file"
|
||||
print(message)
|
||||
# print(message)
|
||||
DataIssue.objects.create(parser="scans", message=message, url=wurl) # set URL to this wallet folder
|
||||
raise
|
||||
else: # no JSON file exists
|
||||
print("--- No JSON exists, so using default copy")
|
||||
# print("--- No JSON exists, so using default copy")
|
||||
waldata = WALLET_BLANK_JSON.copy()
|
||||
|
||||
if not waldata["survex file"]:
|
||||
@@ -490,13 +490,13 @@ def walletedit(request, path=None):
|
||||
for bsf in b:
|
||||
waldata["survex file"].append(bsf.survexfile.path)
|
||||
except:
|
||||
print(f"--- No wallet {wallet} exists in database")
|
||||
# print(f"--- No wallet {wallet} exists in database")
|
||||
return waldata
|
||||
|
||||
def save_json(jsondict):
|
||||
# print(f'--- Wallet directory in :drawings: repo \n {jsondict}')
|
||||
if not os.path.exists(contents_path.parent):
|
||||
print(f"--- No wallet directory in :drawings: repo, so creating it {contents_path.parent}")
|
||||
# print(f"--- No wallet directory in :drawings: repo, so creating it {contents_path.parent}")
|
||||
os.makedirs(contents_path.parent)
|
||||
|
||||
with open(contents_path, "w") as jfile:
|
||||
@@ -510,7 +510,7 @@ def walletedit(request, path=None):
|
||||
# print(f"== make_wallet() Making new wallet {walletname}")
|
||||
try:
|
||||
w, created = Wallet.objects.get_or_create(walletname=walletname)
|
||||
print(f"--- Wallet string {walletname}, wallet object {w} created new?: {created}")
|
||||
# print(f"--- Wallet string {walletname}, wallet object {w} created new?: {created}")
|
||||
if date:
|
||||
w.walletdate = datetime.datetime.now()
|
||||
w.save()
|
||||
@@ -519,12 +519,12 @@ def walletedit(request, path=None):
|
||||
_ = w.year() # sets the walletyear property as a side-effect
|
||||
w.save()
|
||||
except:
|
||||
print(f"!-- Wallet string {walletname}, FAIL TO GET or create WALLET OBJECT")
|
||||
# print(f"!-- Wallet string {walletname}, FAIL TO GET or create WALLET OBJECT")
|
||||
raise
|
||||
return w
|
||||
|
||||
def commit_json(waldata):
|
||||
print(f"commit_json \n..{editor=} \n..{contents_path=}")
|
||||
# print(f"commit_json \n..{editor=} \n..{contents_path=}")
|
||||
|
||||
if "cave" in waldata:
|
||||
label = str(waldata["cave"]).replace("[","").replace("]","")
|
||||
@@ -582,7 +582,7 @@ def walletedit(request, path=None):
|
||||
team.append(p.personname)
|
||||
except:
|
||||
message = " - No associated survex blocks found for this wallet"
|
||||
print(message)
|
||||
# print(message)
|
||||
# print(f" - - - ", wallet_refs, dates, blocknames, team)
|
||||
return wallet_refs, dates, blocknames, team
|
||||
|
||||
@@ -614,7 +614,7 @@ def walletedit(request, path=None):
|
||||
message = f"! {wallet} Specified survex file '{svxf}' in wallet not found on disc, probably renamed."
|
||||
DataIssue.objects.update_or_create(parser="wallets", message=message, url=wurl) # set URL to this wallet folder
|
||||
|
||||
print(message)
|
||||
# print(message)
|
||||
continue
|
||||
|
||||
fpath = svxf.parent / svxf.stem
|
||||
@@ -623,7 +623,7 @@ def walletedit(request, path=None):
|
||||
svxfile = SurvexFile.objects.get(path=fpath)
|
||||
except:
|
||||
message = f"Specified and present survex file '{fpath}'not found in db. Database may be empty. Exception."
|
||||
print(message)
|
||||
# print(message)
|
||||
# This failure will also get picked up by the "S" colour code red or orange
|
||||
try:
|
||||
if svxfile.cave:
|
||||
@@ -638,7 +638,7 @@ def walletedit(request, path=None):
|
||||
team.extend(t)
|
||||
except:
|
||||
message = f"Exception wallet handling for {fpath} invalid survex file link "
|
||||
print(message)
|
||||
# print(message)
|
||||
# This failure will also get picked up by the "S" colour code red or orange
|
||||
|
||||
caves = list(set(caves))
|
||||
@@ -646,7 +646,8 @@ def walletedit(request, path=None):
|
||||
caves = caves[0]
|
||||
|
||||
elif len(caves) > 1:
|
||||
print(
|
||||
pass
|
||||
# print(
|
||||
f" - More than one Cave {caves} in this wallet {wallet}. Not managed in this troggle release."
|
||||
)
|
||||
|
||||
@@ -654,9 +655,9 @@ def walletedit(request, path=None):
|
||||
names = names[0]
|
||||
elif len(names) > 1:
|
||||
names = f"several, please edit: {names}"
|
||||
print(
|
||||
f" - More than one block name is relevant {names} in this wallet {wallet}. Not managed in this troggle release."
|
||||
)
|
||||
# print(
|
||||
# f" - More than one block name is relevant {names} in this wallet {wallet}. Not managed in this troggle release."
|
||||
# )
|
||||
|
||||
cave_refs = list(set(cave_refs))
|
||||
firstdate = None
|
||||
@@ -749,8 +750,8 @@ def walletedit(request, path=None):
|
||||
commit_json(wd)
|
||||
|
||||
else:
|
||||
print("--- INVALID JSON Update form submitted")
|
||||
print(formj.errors)
|
||||
# print("--- INVALID JSON Update form submitted")
|
||||
# print(formj.errors)
|
||||
return render(request, "errors/generic.html", {"message": formj.errors})
|
||||
|
||||
elif (
|
||||
@@ -765,7 +766,7 @@ def walletedit(request, path=None):
|
||||
else: # Creating a wallet or uploading files
|
||||
# NOT editing wallet data, or uploading a file. Should not overwrite metadata at all.
|
||||
if "submitbutton" in request.POST:
|
||||
print(f"--- Submit button value {request.POST['submitbutton']}")
|
||||
# print(f"--- Submit button value {request.POST['submitbutton']}")
|
||||
if request.POST['submitbutton']=="Create":
|
||||
w = WALLET_BLANK_JSON.copy()
|
||||
save_json(w)
|
||||
@@ -774,9 +775,10 @@ def walletedit(request, path=None):
|
||||
|
||||
form = WalletFilesForm(request.POST, request.FILES)
|
||||
if not form.is_valid():
|
||||
print("--- Upload <files form> is invalid, which is correct if just created as there are no files.")
|
||||
pass
|
||||
# print("--- Upload <files form> is invalid, which is correct if just created as there are no files.")
|
||||
else:
|
||||
print(f'--- FORM walletedit multiple BUT EMPTY METADATA supposedly {WALLET_BLANK_JSON["date"]=}')
|
||||
# print(f'--- FORM walletedit multiple BUT EMPTY METADATA supposedly {WALLET_BLANK_JSON["date"]=}')
|
||||
multiple = request.FILES.getlist("uploadfiles")
|
||||
fs = FileSystemStorage(os.path.join(dirpath)) # creates wallet folder if necessary
|
||||
|
||||
@@ -787,7 +789,7 @@ def walletedit(request, path=None):
|
||||
try: # crashes in Django os.chmod call if on WSL, but does save file!
|
||||
saved_filename = fs.save(f.name, content=f)
|
||||
except:
|
||||
print(f"\n !! Permissions failure ?! on attempting to save scanfile {f.name}")
|
||||
# print(f"\n !! Permissions failure ?! on attempting to save scanfile {f.name}")
|
||||
if "saved_filename" in locals():
|
||||
if saved_filename.is_file():
|
||||
actual_saved.append(saved_filename)
|
||||
@@ -858,7 +860,7 @@ def walletedit(request, path=None):
|
||||
context = {}
|
||||
if not waldata: # should always be true as populated by blank data if json file doesn't exist
|
||||
message = f" !! No Wallet data initialised or read ! Should not happen."
|
||||
print(message)
|
||||
# print(message)
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
|
||||
refs = []
|
||||
@@ -880,7 +882,7 @@ def walletedit(request, path=None):
|
||||
person_id = who_is_this(year, person)
|
||||
except:
|
||||
continue
|
||||
print(f"walletedit: {person}, {person_id}")
|
||||
# print(f"walletedit: {person}, {person_id}")
|
||||
persons.append(Person.objects.get(slug=person_id))
|
||||
|
||||
|
||||
@@ -917,7 +919,7 @@ def walletedit(request, path=None):
|
||||
except: # creating a wallet for an expo that does not exist perhaps
|
||||
message = f"Trying to access an Expo for '{year}' which does not exist (yet)."
|
||||
message += " See /handbook/computing/newyear.html"
|
||||
print(message)
|
||||
# print(message)
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
if samedate:
|
||||
svxothers = SurvexFile.objects.filter(survexblock__date=samedate).distinct()
|
||||
|
||||
Reference in New Issue
Block a user