2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-01-19 09:22:32 +00:00

Form creates wallet folder and contents.json

This commit is contained in:
Philip Sargent 2022-03-15 17:04:43 +00:00
parent fac748d2e2
commit 3390f51049
4 changed files with 90 additions and 19 deletions

View File

@ -19,7 +19,7 @@ by looking inside the file before being served.
need to check if inavlid query string is invalid, or produces multiple replies
and render a user-friendly error page.
'''
def singlewallet(request, path):
#print [ s.walletname for s in Wallet.objects.all() ]
try:

View File

@ -1,5 +1,6 @@
import re, os
import subprocess
import json
from pathlib import Path
from django import forms
@ -15,6 +16,7 @@ from django.core.files.storage import FileSystemStorage, default_storage
#from troggle import settings
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.scans import wallet_blank_json, wallet_blank_html, contentsjson, indexhtml
# from databaseReset import reinit_db # don't do this. databaseRest runs code *at import time*
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
from troggle.core.models.caves import LogbookEntry, QM, Cave, PersonTrip
@ -75,11 +77,13 @@ def scanupload(request, wallet=None):
if int(wnumber) == 0:
prev = f'{int(wnumber):02d}'
context = {'year': year, 'prev': prev, 'next': next, 'prevy': prevy, 'nexty': nexty}
wallet = wallet.replace(':','#')
dirpath = Path(settings.SURVEY_SCANS, year, wallet)
walletdata = dirpath / contentsjson
form = FilesForm()
@ -90,7 +94,7 @@ def scanupload(request, wallet=None):
if form.is_valid():
f = request.FILES["uploadfiles"]
multiple = request.FILES.getlist('uploadfiles')
fs = FileSystemStorage(os.path.join(settings.SURVEY_SCANS, year, wallet))
fs = FileSystemStorage(os.path.join(dirpath)) # creates wallet folder if necessary
actual_saved = []
if multiple:
@ -98,29 +102,45 @@ def scanupload(request, wallet=None):
actual_saved.append( fs.save(f.name, content=f) )
# print(f'! - FORM scanupload multiple {actual_saved}')
filesaved = True
# Wallet folder created, but index and contents.json need to be created.
contents_path = dirpath / contentsjson
if not contents_path.is_file(): # double-check
with open(contents_path, "w") as json_file:
json.dump(wallet_blank_json, json_file, sort_keys=True, indent = 1)
index_path = dirpath / indexhtml
if not index_path.is_file(): # double-check
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 = []
dirs = []
# print(f'! - FORM scanupload - start {wallet} {dirpath}')
try:
for f in dirpath.iterdir():
if f.is_dir():
dirs.append(f.name)
if f.is_file():
if f.name != 'contents.json' and f.name != 'walletindex.html':
files.append(f.name)
except FileNotFoundError:
files.append('(no wallet yet - would be created)')
if len(files) ==0 :
files.append('(no image files in wallet)')
if dirpath.is_dir():
create = False
try:
for f in dirpath.iterdir():
if f.is_dir():
dirs.append(f.name)
if f.is_file():
if f.name != 'contents.json' and f.name != 'walletindex.html':
files.append(f.name)
except FileNotFoundError:
files.append('(no wallet yet. It would be created if you upload a scan)')
else:
create = True
if len(files) >0 :
files = sorted(files)
if dirs:
dirs = sorted(dirs)
return render(request, 'scanuploadform.html',
{'form': form, 'wallet': wallet, **context, 'files': files, 'dirs': dirs, 'filesaved': filesaved, 'actual_saved': actual_saved})
{'form': form, 'wallet': wallet, **context, 'files': files, 'dirs': dirs, 'create': create, 'filesaved': filesaved, 'actual_saved': actual_saved})
@login_required_if_public
def photoupload(request, folder=None):

View File

@ -16,6 +16,44 @@ from troggle.core.utils import save_carefully, GetListDir
'''Searches through all the survey scans directories (wallets) in expofiles, looking for images to be referenced.
'''
contentsjson = "contents.json"
indexhtml = "walletindex.html"
wallet_blank_json = {
"cave": "",
"date": "",
"description url": "/caves",
"description written": False,
"electronic survey": False,
"elev drawn": False,
"elev not required": False,
"name": "",
"people": [
"Unknown"
],
"plan drawn": False,
"plan not required": False,
"qms written": False,
"survex file": [],
"survex not required": False,
"website updated": False}
wallet_blank_html = '''<html><body><H1>Wallet WALLET</H1>
<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>
<p>Date: </p><p>People: Unknown,</p>
<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.
<p>Survex file: not identified yet
<H2>Issues</H2>
<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>Tunnel / Therion drawing files need drawing</p>
<H2>Files</H2>
<UL>
</UL>
</body></html>
'''
def get_or_create_placeholder(year):
""" All surveys must be related to a logbookentry. We don't have a way to

View File

@ -32,16 +32,29 @@
<p>
<b>File(s) saved as <br>
{% for f in actual_saved %}
<em>{{f}}</em> <br>
<em>{{f}}</em> <br></b>
{% endfor %}
<br><br>Upload more?</b>
</p>
<br>
{% endif %}
<p>
{% for f in files %}
<a href="/expofiles/surveyscans/{{year}}/{{wallet|urlencode}}/{{f}}">{{ f}}</a><br />
{% empty %}
<p>&lt;No files here&gt;
{% endfor %}
</p>
</div> {% endblock %}
{% if create %}
This online wallet does not yet exist.
<br>It will be created and initialised automatically when you upload a file.
{% endif %}
<p><em>
<a href="/expofiles/surveyscans/{{year}}/{{wallet|urlencode}}/walletindex.html">Wallet status page</a>
<br />
<a href="/expofiles/surveyscans/{{year}}/walletindex.html">Wallet index for this year</a>
</em>
</div>
<hr />
{% endblock %}