forked from expo/troggle
Fix wallets scan upload faults
This commit is contained in:
parent
b093d00ff4
commit
284e044a03
@ -23,7 +23,7 @@ from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
|
|||||||
#from troggle import settings
|
#from troggle import settings
|
||||||
from troggle.parsers.imports import import_caves, import_people, import_surveyscans
|
from troggle.parsers.imports import import_caves, import_people, import_surveyscans
|
||||||
from troggle.parsers.imports import import_logbooks, import_QMs, import_drawingsfiles, import_survex
|
from troggle.parsers.imports import import_logbooks, import_QMs, import_drawingsfiles, import_survex
|
||||||
from troggle.parsers.scans import wallet_blank_json, wallet_blank_html, contentsjson, indexhtml, CopyWalletData
|
from troggle.parsers.scans import wallet_blank_json, contentsjson, CopyWalletData
|
||||||
# from databaseReset import reinit_db # don't do this. databaseRest runs code *at import time*
|
# from databaseReset import reinit_db # don't do this. databaseRest runs code *at import time*
|
||||||
from troggle.core.models.troggle import DataIssue
|
from troggle.core.models.troggle import DataIssue
|
||||||
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
|
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
|
||||||
@ -64,6 +64,9 @@ class FilesRenameForm(forms.Form): # not a model-form, just a form-form
|
|||||||
uploadfiles = forms.FileField()
|
uploadfiles = forms.FileField()
|
||||||
renameto = forms.CharField(strip=True, required=False)
|
renameto = forms.CharField(strip=True, required=False)
|
||||||
|
|
||||||
|
class WalletGotoForm(forms.Form): # not a model-form, just a form-form
|
||||||
|
walletgoto = forms.CharField(strip=True, required=False)
|
||||||
|
|
||||||
class TextForm(forms.Form): # not a model-form, just a form-form
|
class TextForm(forms.Form): # not a model-form, just a form-form
|
||||||
photographer = forms.CharField(strip=True)
|
photographer = forms.CharField(strip=True)
|
||||||
|
|
||||||
@ -200,6 +203,10 @@ def scanupload(request, path=None):
|
|||||||
'''Upload scanned image files into a wallet on /expofiles
|
'''Upload scanned image files into a wallet on /expofiles
|
||||||
Also display AND EDIT the contents.json data in the wallet.
|
Also display AND EDIT the contents.json data in the wallet.
|
||||||
|
|
||||||
|
The Wallet object and the contents.json file are only created when the user
|
||||||
|
edits the JSON data, not when they upload files. This may be a bad idea
|
||||||
|
as the wallet will not appear in reports untilt his is done.
|
||||||
|
|
||||||
This does NOT use a Django model linked to a Django form. Just a simple Django form.
|
This does NOT use a Django model linked to a Django form. Just a simple Django form.
|
||||||
You will find the Django documentation on forms very confusing, This is simpler.
|
You will find the Django documentation on forms very confusing, This is simpler.
|
||||||
|
|
||||||
@ -269,7 +276,6 @@ def scanupload(request, path=None):
|
|||||||
# Also lots of hassle with lists of strings interpreted as a single string
|
# Also lots of hassle with lists of strings interpreted as a single string
|
||||||
# Unset checkboxes do not return any value, checked ones return "True". So need initialising to False
|
# Unset checkboxes do not return any value, checked ones return "True". So need initialising to False
|
||||||
if formj.is_valid():
|
if formj.is_valid():
|
||||||
#print(f'--- JSON Update form is VALID, saving to {contents_path}')
|
|
||||||
posted = request.POST.copy()
|
posted = request.POST.copy()
|
||||||
posted.pop("csrfmiddlewaretoken") # discard this
|
posted.pop("csrfmiddlewaretoken") # discard this
|
||||||
wd = wallet_blank_json
|
wd = wallet_blank_json
|
||||||
@ -295,11 +301,17 @@ def scanupload(request, path=None):
|
|||||||
wd["survex file"][i] = elem.strip()
|
wd["survex file"][i] = elem.strip()
|
||||||
#print(f'--- {wd["survex file"]} - {type(wd["survex file"])}')
|
#print(f'--- {wd["survex file"]} - {type(wd["survex file"])}')
|
||||||
|
|
||||||
|
newfolder = contents_path.parent
|
||||||
|
print(f'--- wallet directory in :drawings: repo {newfolder=}')
|
||||||
|
if not os.path.exists(contents_path.parent):
|
||||||
|
print(f'--- No wallet directory in :drawings: repo, so creating it')
|
||||||
|
os.makedirs(contents_path.parent)
|
||||||
|
|
||||||
with open(contents_path, "w") as jfile:
|
with open(contents_path, "w") as jfile:
|
||||||
json.dump(wd, jfile, indent = 1)
|
json.dump(wd, jfile, indent = 1)
|
||||||
# print(f'--- FINISHED saving to JSON\n')
|
print(f'--- FINISHED saving to JSON at {contents_path}')
|
||||||
|
|
||||||
# This copies the new data to the drawings repo and commits it
|
# This commits it,
|
||||||
# needs the troggle object wallet, not a string
|
# needs the troggle object wallet, not a string
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -312,6 +324,7 @@ def scanupload(request, path=None):
|
|||||||
print(f'wallet string {wallet}, FAIL TO GET or create WALLET OBJECT')
|
print(f'wallet string {wallet}, FAIL TO GET or create WALLET OBJECT')
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
# now we do the git add and commit
|
||||||
destfolder = contents_path.parent
|
destfolder = contents_path.parent
|
||||||
dr_add = subprocess.run([git, "add", contentsjson], cwd=destfolder, capture_output=True, text=True)
|
dr_add = subprocess.run([git, "add", contentsjson], cwd=destfolder, capture_output=True, text=True)
|
||||||
if dr_add.returncode != 0:
|
if dr_add.returncode != 0:
|
||||||
@ -333,6 +346,13 @@ def scanupload(request, path=None):
|
|||||||
print(formj.errors)
|
print(formj.errors)
|
||||||
return render(request,'errors/generic.html', {'message': formj.errors})
|
return render(request,'errors/generic.html', {'message': formj.errors})
|
||||||
|
|
||||||
|
elif "walletgoto" in request.POST: # not editing wallet data, uploading a file.. going direct to a named wallet
|
||||||
|
formg = WalletGotoForm(request.POST,request.FILES)
|
||||||
|
if formg.is_valid():
|
||||||
|
walletgoto = request.POST["walletgoto"]
|
||||||
|
|
||||||
|
return HttpResponseRedirect(f'/scanupload/{walletgoto.replace("#",":")}')
|
||||||
|
|
||||||
else: # not editing wallet data, uploading a file..
|
else: # not editing wallet data, uploading a file..
|
||||||
form = FilesForm(request.POST,request.FILES)
|
form = FilesForm(request.POST,request.FILES)
|
||||||
|
|
||||||
@ -354,15 +374,18 @@ def scanupload(request, path=None):
|
|||||||
# print(f'! - FORM scanupload multiple {actual_saved}')
|
# print(f'! - FORM scanupload multiple {actual_saved}')
|
||||||
filesaved = True
|
filesaved = True
|
||||||
|
|
||||||
if not contents_path.is_file(): # double-check
|
# Don't do this when uploading a file.
|
||||||
with open(contents_path, "w") as json_file:
|
# The contents.json file will be created when the wallet data is edited for the first time.
|
||||||
json.dump(wallet_blank_json, json_file, sort_keys=True, indent = 1)
|
# if not contents_path.is_file(): # double-check: it doesn't exist yet so create it when uploading a file.
|
||||||
index_path = dirpath / indexhtml
|
# with open(contents_path, "w") as json_file:
|
||||||
if not index_path.is_file(): # double-check
|
# json.dump(wallet_blank_json, json_file, sort_keys=True, indent = 1)
|
||||||
thishtml = wallet_blank_html.replace("YEAR", str(year))
|
|
||||||
thishtml = thishtml.replace("WALLET", str(wallet))
|
# index_path = dirpath / indexhtml
|
||||||
with open(index_path, "w") as html_file:
|
# if not index_path.is_file(): # double-check it doesn't exist yet
|
||||||
html_file.write(thishtml )
|
# thishtml = wallet_blank_html.replace("YEAR", str(year))
|
||||||
|
# thishtml = thishtml.replace("WALLET", str,(wallet))
|
||||||
|
# with open(index_path, "w") as html_file:
|
||||||
|
# html_file.write(thishtml )
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
dirs = []
|
dirs = []
|
||||||
@ -374,7 +397,6 @@ def scanupload(request, path=None):
|
|||||||
if f.is_dir():
|
if f.is_dir():
|
||||||
dirs.append(f.name)
|
dirs.append(f.name)
|
||||||
if f.is_file():
|
if f.is_file():
|
||||||
if f.name != 'contents.json' and f.name != 'walletindex.html':
|
|
||||||
files.append(f.name)
|
files.append(f.name)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
files.append('(no wallet yet. It would be created if you upload a scan)')
|
files.append('(no wallet yet. It would be created if you upload a scan)')
|
||||||
|
@ -18,7 +18,7 @@ from troggle.core.utils import save_carefully, GetListDir
|
|||||||
for tunnel and therion files
|
for tunnel and therion files
|
||||||
'''
|
'''
|
||||||
|
|
||||||
todo='''
|
todo='''Rename functions more consistently between tunnel and therion variants
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def find_dwg_file(dwgfile, path):
|
def find_dwg_file(dwgfile, path):
|
||||||
@ -104,7 +104,7 @@ def findwalletimage(therionfile, foundpath):
|
|||||||
else:
|
else:
|
||||||
message = f'! Scanned file {scanfilename} mentioned in "{therionfile.dwgpath}" is not actually found in {wallet.walletname}'
|
message = f'! Scanned file {scanfilename} mentioned in "{therionfile.dwgpath}" is not actually found in {wallet.walletname}'
|
||||||
wurl = f'/survey_scans/{wallet.walletname}/'.replace("#",":")
|
wurl = f'/survey_scans/{wallet.walletname}/'.replace("#",":")
|
||||||
print(message)
|
# print(message)
|
||||||
DataIssue.objects.create(parser='Therion', message=message, url = wurl)
|
DataIssue.objects.create(parser='Therion', message=message, url = wurl)
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ from troggle.core.views.scans import datewallet
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
contentsjson = "contents.json"
|
contentsjson = "contents.json"
|
||||||
indexhtml = "walletindex.html"
|
#indexhtml = "walletindex.html"
|
||||||
git = settings.GIT
|
git = settings.GIT
|
||||||
|
|
||||||
# to do: create a 'low priority' field, so that any such wallet does not appear in summary reports
|
# to do: create a 'low priority' field, so that any such wallet does not appear in summary reports
|
||||||
@ -44,22 +44,22 @@ wallet_blank_json = {
|
|||||||
"survex not required": False,
|
"survex not required": False,
|
||||||
"website updated": False}
|
"website updated": False}
|
||||||
|
|
||||||
wallet_blank_html = '''<html><body><H1>Wallet WALLET</H1>
|
# wallet_blank_html = '''<html><body><H1>Wallet WALLET</H1>
|
||||||
<p>List of trips: <a href="http://expo.survex.com/expedition/YEAR">expedition/YEAR</a>
|
# <p>List of trips: <a href="http://expo.survex.com/expedition/YEAR">expedition/YEAR</a>
|
||||||
- troggle-processed .svx files and logbook entries on server</p>
|
# - troggle-processed .svx files and logbook entries on server</p>
|
||||||
<p>Date: </p><p>People: Unknown,</p>
|
# <p>Date: </p><p>People: Unknown,</p>
|
||||||
<p>Cave <a href='http://expo.survex.com/caves/'>Guidebook description</a>
|
# <p>Cave <a href='http://expo.survex.com/caves/'>Guidebook description</a>
|
||||||
- A description is indicated as being needed, so may need adding into this cave page.
|
# - A description is indicated as being needed, so may need adding into this cave page.
|
||||||
<p>Survex file: not identified yet
|
# <p>Survex file: not identified yet
|
||||||
<H2>Issues</H2>
|
# <H2>Issues</H2>
|
||||||
<p>The description needs writing</p>
|
# <p>The description needs writing</p>
|
||||||
<p>The QMs needs writing</p><p>The website is marked as needing updating (using the guidebook description)</p>
|
# <p>The QMs needs writing</p><p>The website is marked as needing updating (using the guidebook description)</p>
|
||||||
<p>Tunnel / Therion drawing files need drawing</p>
|
# <p>Tunnel / Therion drawing files need drawing</p>
|
||||||
<H2>Files</H2>
|
# <H2>Files</H2>
|
||||||
<UL>
|
# <UL>
|
||||||
</UL>
|
# </UL>
|
||||||
</body></html>
|
# </body></html>
|
||||||
'''
|
# '''
|
||||||
|
|
||||||
def CheckEmptyDate(wallet):
|
def CheckEmptyDate(wallet):
|
||||||
'''If date is not set, get it from a linked survex file.
|
'''If date is not set, get it from a linked survex file.
|
||||||
|
@ -1528,6 +1528,12 @@ def LoadSurvexBlocks():
|
|||||||
survexblockroot = SurvexBlock(name=ROOTBLOCK, survexpath="", cave=None, survexfile=survexfileroot,
|
survexblockroot = SurvexBlock(name=ROOTBLOCK, survexpath="", cave=None, survexfile=survexfileroot,
|
||||||
legsall=0, legslength=0.0)
|
legsall=0, legslength=0.0)
|
||||||
# crashes here sometimes on MariaDB complaining that cave_id should not be null. But it should be.
|
# crashes here sometimes on MariaDB complaining that cave_id should not be null. But it should be.
|
||||||
|
#django.db.utils.IntegrityError: (1048, "Column 'cave_id' cannot be null")
|
||||||
|
# fix by restarting db on server
|
||||||
|
# sudo service mariadb stop
|
||||||
|
# sudo service mariadb start
|
||||||
|
|
||||||
|
|
||||||
survexblockroot.save()
|
survexblockroot.save()
|
||||||
|
|
||||||
print(' - Loading Survex Blocks...')
|
print(' - Loading Survex Blocks...')
|
||||||
|
@ -10,6 +10,18 @@
|
|||||||
<h2>Wallet {{wallet}}</h2>
|
<h2>Wallet {{wallet}}</h2>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<form method ='post' style="text-align: center">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button class="fancybutton" style="padding: 0.5em 25px; font-size: 80%;" type = "submit" value = "Go to" >
|
||||||
|
Go directly to this wallet: →
|
||||||
|
</button>
|
||||||
|
<input
|
||||||
|
label = "WalletGoto" name = "walletgoto" size="7"
|
||||||
|
title="Wallet name to go to directly"
|
||||||
|
placeholder="2022#11" />
|
||||||
|
|
||||||
|
|
||||||
|
</form>
|
||||||
<p style="font-family: monospace; font-weight: bold; font-size: 130%; text-align: center">
|
<p style="font-family: monospace; font-weight: bold; font-size: 130%; text-align: center">
|
||||||
<a style="font-weight: normal;" href="/scanupload/{{prevy}}:01">{{prevy}}</a>
|
<a style="font-weight: normal;" href="/scanupload/{{prevy}}:01">{{prevy}}</a>
|
||||||
...
|
...
|
||||||
@ -20,6 +32,7 @@
|
|||||||
<a style="font-weight: normal;" href="/scanupload/{{nexty}}:01">{{nexty}}</a>
|
<a style="font-weight: normal;" href="/scanupload/{{nexty}}:01">{{nexty}}</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
<div style = "max-width:35%; margin-left:20%; text-align: center; " >
|
<div style = "max-width:35%; margin-left:20%; text-align: center; " >
|
||||||
<form method ='post' enctype ="multipart/form-data">
|
<form method ='post' enctype ="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
@ -53,9 +66,10 @@
|
|||||||
{% if create %}
|
{% if create %}
|
||||||
This online wallet does not yet exist.
|
This online wallet does not yet exist.
|
||||||
{% if user.username %}
|
{% if user.username %}
|
||||||
<br>It will be created and initialised automatically when you upload a file.
|
<br>It will be created and initialised automatically when you upload a file, and then edit the date in the form below and save it.
|
||||||
{% else %}
|
{% else %}
|
||||||
<br>It will be created and initialised automatically when you upload a file, but you need to log on first.
|
<br>It will be created and initialised automatically when you upload a file, and then edit the date in the form below and save it.
|
||||||
|
<br>But you need to log in first <a href=/accounts/login/">Log In </a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user