diff --git a/core/views/scans.py b/core/views/scans.py index 3acdbae..6e380c2 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -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: diff --git a/core/views/uploads.py b/core/views/uploads.py index d227bda..3ccc587 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -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): diff --git a/parsers/scans.py b/parsers/scans.py index 161c8b8..351441c 100644 --- a/parsers/scans.py +++ b/parsers/scans.py @@ -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 = '''
List of trips: expedition/YEAR +- troggle-processed .svx files and logbook entries on server
+Date:
People: Unknown,
+Cave Guidebook description +- A description is indicated as being needed, so may need adding into this cave page. +
Survex file: not identified yet +
The description needs writing
+The QMs needs writing
The website is marked as needing updating (using the guidebook description)
+Tunnel / Therion drawing files need drawing
+
File(s) saved as
{% for f in actual_saved %}
- {{f}}
+ {{f}}
{% endfor %}
-
Upload more?
{% for f in files %}
{{ f}}
+ {% empty %}
+
<No files here> {% endfor %}
- {% endblock %} + {% if create %} + This online wallet does not yet exist. +
+Wallet status page
+
+Wallet index for this year
+
+
+
+