mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-17 09:07:19 +00:00
initial GPX track averager
This commit is contained in:
@@ -80,6 +80,9 @@ class PhotographerForm(forms.Form): # not a model-form, just a form-form
|
||||
class GPXuploadForm(forms.Form): # not a model-form, just a form-form
|
||||
prospector = forms.CharField(strip=True)
|
||||
|
||||
class gpxfixForm(forms.Form): # not a model-form, just a form-form
|
||||
prospector = forms.CharField(strip=True)
|
||||
|
||||
class FilesRenameForm(forms.Form): # not a model-form, just a form-form
|
||||
"""Used only for renaming photos in /expofiles/photos/
|
||||
which is not a git repo
|
||||
@@ -563,6 +566,155 @@ def gpxupload(request, folder=None):
|
||||
},
|
||||
)
|
||||
|
||||
@login_required_if_public
|
||||
def gpxfix(request):
|
||||
"""Upload a GPX file containing a single track which is actually a single static point: for averaging
|
||||
"""
|
||||
def gpxvalid(name):
|
||||
if Path(name).suffix.lower() in [".xml", ".gpx"]:
|
||||
return True # dangerous, we should check the actual file binary signature
|
||||
return False
|
||||
|
||||
year = current_expo() # read thsi from the GPX file
|
||||
filesaved = False
|
||||
actual_saved = []
|
||||
|
||||
context = {"year": year, "placeholder": "AnathemaDevice"}
|
||||
|
||||
yearpath = Path(settings.EXPOFILES) / "gpsfix" / year
|
||||
|
||||
|
||||
folder = "" # improve this later
|
||||
dirpath = yearpath
|
||||
urlfile = f"/expofiles/gpsfix/{year}"
|
||||
urldir = f"/gpxfix/{year}"
|
||||
|
||||
|
||||
print(f"gpxfix() {folder=} {dirpath=} {urlfile=} {urldir=}")
|
||||
form = FilesRenameForm()
|
||||
formd = gpxfixForm()
|
||||
print(f"gpxfix() {form=} {formd=} ")
|
||||
|
||||
|
||||
if request.method == "POST":
|
||||
print(f"gpxfix() method=POST")
|
||||
for i in request.POST:
|
||||
print(" ",i)
|
||||
|
||||
try:
|
||||
(yearpath).mkdir(parents=True, exist_ok=True)
|
||||
except:
|
||||
message = f'\n !! Permissions failure ?! 0 attempting to mkdir "{(yearpath)}"'
|
||||
print(message)
|
||||
raise
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
|
||||
if "prospector" in request.POST:
|
||||
print(f"gpxfix() {request.POST=}\n {request.POST['prospector']=}")
|
||||
formd = gpxfixForm(request.POST)
|
||||
if formd.is_valid():
|
||||
newprospector = sanitize_name(request.POST["prospector"])
|
||||
print(f"gpxfix() {newprospector=}")
|
||||
else:
|
||||
print(f"gpxfix() no prospector field")
|
||||
print(f"gpxfix() {request.FILES=}")
|
||||
for i in request.FILES:
|
||||
print(" ",i)
|
||||
|
||||
form = FilesRenameForm(request.POST, request.FILES)
|
||||
print(f"gpxfix() is the FilesRenameForm valid? {form=}")
|
||||
for i in form:
|
||||
print(" ",i)
|
||||
|
||||
if not form.is_valid():
|
||||
print(f"gpxfix() Form is not valid {form=}")
|
||||
else:
|
||||
print(f"gpxfix() about to look at request.FILES")
|
||||
f = request.FILES["uploadfiles"]
|
||||
multiple = request.FILES.getlist("uploadfiles")
|
||||
# NO CHECK that the files being uploaded are image files
|
||||
fs = FileSystemStorage(dirpath)
|
||||
|
||||
renameto = sanitize_name(request.POST["renameto"])
|
||||
|
||||
actual_saved = []
|
||||
if multiple:
|
||||
if len(multiple) == 1:
|
||||
if renameto != "":
|
||||
try: # crashes in Django os.chmod call if on WSL, but does save file!
|
||||
saved_filename = fs.save(renameto, content=f)
|
||||
except:
|
||||
print(
|
||||
f'\n !! Permissions failure ?! 1 attempting to save "{f.name}" in "{dirpath}" {renameto=}'
|
||||
)
|
||||
if "saved_filename" in locals():
|
||||
if saved_filename.is_file():
|
||||
actual_saved.append(saved_filename)
|
||||
filesaved = True
|
||||
else: # multiple is the uploaded content
|
||||
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 ?! 2 attempting to save "{f.name}" in "{dirpath}" {renameto=}'
|
||||
)
|
||||
if "saved_filename" in locals():
|
||||
if saved_filename.is_file():
|
||||
actual_saved.append(saved_filename)
|
||||
filesaved = True
|
||||
else: # multiple is a list of content
|
||||
for f in multiple:
|
||||
if gpxvalid(f.name):
|
||||
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 ?! 3 attempting to save "{f.name}" in "{dirpath}" {renameto=}'
|
||||
)
|
||||
if "saved_filename" in locals():
|
||||
if saved_filename.is_file():
|
||||
actual_saved.append(saved_filename)
|
||||
filesaved = True
|
||||
else:
|
||||
print(f"gpxfix(): not a GPX file {f.name=}")
|
||||
|
||||
print(f"gpxfix() drop through")
|
||||
files = []
|
||||
dirs = []
|
||||
try:
|
||||
for f in dirpath.iterdir():
|
||||
if f.is_dir():
|
||||
dirs.append(f.name)
|
||||
if f.is_file():
|
||||
files.append(f.name)
|
||||
except FileNotFoundError:
|
||||
files.append("(no folder yet - would be created)")
|
||||
except Exception as e:
|
||||
print(f"gpxfix() EXCEPTION\n {e}")
|
||||
if len(files) > 0:
|
||||
files = sorted(files)
|
||||
|
||||
if dirs:
|
||||
dirs = sorted(dirs)
|
||||
|
||||
print(f"gpxfix() about to render..")
|
||||
return render(
|
||||
request,
|
||||
"gpxfixform.html",
|
||||
{
|
||||
"form": form,
|
||||
**context,
|
||||
"urlfile": urlfile,
|
||||
"urldir": urldir,
|
||||
"folder": folder,
|
||||
"files": files,
|
||||
"dirs": dirs,
|
||||
"filesaved": filesaved,
|
||||
"actual_saved": actual_saved,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@login_required_if_public
|
||||
def dwgupload(request, folder=None, gitdisable="no"):
|
||||
"""Upload DRAWING files (tunnel or therion) into the upload folder in :drawings
|
||||
|
||||
61
templates/gpxfixform.html
Normal file
61
templates/gpxfixform.html
Normal file
@@ -0,0 +1,61 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Upload GPX file for a *fix{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
||||
|
||||
<h2>Upload GPX file for a *fix</h2>
|
||||
|
||||
<div style = "max-width:35%; margin-left:20%; text-align: center; " >
|
||||
<form method ='post' enctype ="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<br>
|
||||
<input class="fancybutton2" type = "file"
|
||||
name = "uploadfiles" id="uploadfiles" />
|
||||
<br><br><br>
|
||||
<input class="fancybutton2" style="padding: 0.5em 25px; margin-left: 125px"
|
||||
label = "Rename to" name = "renameto" id="renameto"
|
||||
pattern="[A-Za-z][A-Za-z0-9_-\.]*"/>
|
||||
<br />
|
||||
<label
|
||||
style="padding: 0.5em 25px; margin-left: 110px"
|
||||
for="renameto">You can rename it<br></label>
|
||||
<br><br><br>
|
||||
<button class="fancybutton2" style="padding: 0.5em 25px; margin-left: 155px" type = "submit" value = "Upload" >
|
||||
Upload
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<div style = "max-width:29%; margin-left:20%; text-align: left" >
|
||||
{% if filesaved %}
|
||||
<p>
|
||||
<b>File(s) saved as <br>
|
||||
{% for f in actual_saved %}
|
||||
<em>{{f}}</em> <br>
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<strong style="font-size: 110%;">Files:</strong><br>
|
||||
{% for f in files %}
|
||||
<a href="{{urlfile|urlencode}}/{{f|urlencode}}">{{f}}</a><br />
|
||||
{% empty %}
|
||||
<p><No files here>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<p>You can upload your GPX track which will be averaged into a single *fix
|
||||
<p>Note that only GPX files are accepted: all other types of files are refused.
|
||||
<hr>
|
||||
|
||||
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<p>
|
||||
|
||||
<hr />
|
||||
|
||||
|
||||
{% endblock %}
|
||||
3
urls.py
3
urls.py
@@ -64,7 +64,7 @@ from troggle.core.views.prospect import prospecting
|
||||
from troggle.core.views.user_registration import register, newregister, reset_done, ExpoPasswordResetForm
|
||||
from troggle.core.views.scans import allscans, cavewallets, scansingle, walletslistperson, walletslistyear
|
||||
from troggle.core.views.signup import signup, signupok
|
||||
from troggle.core.views.uploads import dwgupload, expofilerename, gpxupload, photoupload
|
||||
from troggle.core.views.uploads import dwgupload, expofilerename, gpxupload, photoupload, gpxfix
|
||||
from troggle.core.views.wallets_edit import walletedit
|
||||
|
||||
# crashes when run from wsgi on new server OS:
|
||||
@@ -180,6 +180,7 @@ trogglepatterns = [
|
||||
path('walletedit/<path:path>', walletedit, name='walletedit'), # path=2020#01
|
||||
path('photoupload', photoupload, name='photoupload'), # restricted to current year
|
||||
path('photoupload/<path:folder>', photoupload, name='photoupload'), # restricted to current year
|
||||
path('gpxfix', gpxfix, name='gpxfix'), # upload GPX 'track' for a single fix
|
||||
path('gpxupload', gpxupload, name='gpxupload'), # restricted to current year
|
||||
path('gpxupload/<path:folder>', gpxupload, name='gpxupload'), # restricted to current year
|
||||
path('dwgupload/<path:folder>', dwgupload, name='dwgupload'),
|
||||
|
||||
Reference in New Issue
Block a user