List the logbook trips and other svx files of the same date

This commit is contained in:
Philip Sargent 2022-09-14 00:31:37 +03:00
parent 04696b7b80
commit 9410dda69e
2 changed files with 64 additions and 21 deletions

View File

@ -4,6 +4,7 @@ import json
import settings import settings
import urllib import urllib
import operator import operator
import datetime
from pathlib import Path from pathlib import Path
from functools import reduce from functools import reduce
@ -32,6 +33,7 @@ from troggle.core.models.survex import DrawingFile, Wallet, SurvexBlock, SurvexF
from troggle.core.views.scans import oldwallet from troggle.core.views.scans import oldwallet
from troggle.core.views.caves import getCave from troggle.core.views.caves import getCave
from .auth import login_required_if_public from .auth import login_required_if_public
#from django.views.decorators.csrf import ensure_csrf_cookie, csrf_exempt #from django.views.decorators.csrf import ensure_csrf_cookie, csrf_exempt
@ -225,6 +227,8 @@ 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.
This is the main wallet display and edit page.
The Wallet object and the contents.json file are created when the user The Wallet object and the contents.json file are created when the user
first uploads files. first uploads files.
@ -322,6 +326,8 @@ def scanupload(request, path=None):
print(message) print(message)
return render(request,'errors/generic.html', {'message': message}) return render(request,'errors/generic.html', {'message': message})
def get_logbook_trips():
return None
checkboxes = ["description written", "survex not required", "qms written", "website updated", checkboxes = ["description written", "survex not required", "qms written", "website updated",
"plan not required", "plan drawn", "elev not required", "elev drawn", "electronic survey" ] "plan not required", "plan drawn", "elev not required", "elev drawn", "electronic survey" ]
@ -446,8 +452,9 @@ def scanupload(request, path=None):
save_json(waldata) save_json(waldata)
make_wallet(wallet) make_wallet(wallet)
commit_json(waldata) commit_json(waldata)
#
# Not a POST, so a GET starts here. And also control gets here after a POST is processed. # Not a POST, so a GET starts here. And also control gets here after a POST is processed.
#
files = [] files = []
dirs = [] dirs = []
# print(f'! - FORM scanupload - start {wallet} {dirpath}') # print(f'! - FORM scanupload - start {wallet} {dirpath}')
@ -482,6 +489,7 @@ def scanupload(request, path=None):
chkplannr = "" chkplannr = ""
chkpland = "" chkpland = ""
svxfiles = [] svxfiles = []
trips =[]
checked = {} checked = {}
context = {} context = {}
if waldata: # should always be true as populated by blank data if json file doesn't exist if waldata: # should always be true as populated by blank data if json file doesn't exist
@ -584,6 +592,24 @@ def scanupload(request, path=None):
if not waldata["description url"]: if not waldata["description url"]:
waldata["description url"]="" waldata["description url"]=""
# find trips and survex files of the same date
datestr = waldata["date"].replace('.','-')
try:
samedate = datetime.date.fromisoformat(datestr)
except ValueError:
# probably a single digit day number. HACKUS MAXIMUS.
# clearly we need to fix this when we first import date strings..
datestr = datestr[:-1] + '0' + datestr[-1]
print(f' - {datestr=} ')
samedate = datetime.date.fromisoformat(datestr)
trips = LogbookEntry.objects.filter(date=samedate)
thisexpo = Expedition.objects.get(year=int(year))
expeditionday = thisexpo.get_expedition_day(samedate)
#print(f' - {thisexpo=} {expeditionday=}')
svxothers = SurvexBlock.objects.filter(expeditionday=expeditionday)
#print(f' - {thisexpo=} {expeditionday=} {svxothers=}')
#Survex and survex complaints, comes from json file on disc, not as pre-populated as above #Survex and survex complaints, comes from json file on disc, not as pre-populated as above
complaints, caveobject = get_complaints([], waldata, svxfiles, files, wallet, wurl) complaints, caveobject = get_complaints([], waldata, svxfiles, files, wallet, wurl)
# print(f' - {caveobject=}') # print(f' - {caveobject=}')
@ -598,6 +624,8 @@ def scanupload(request, path=None):
context = {'year': year, 'prev': prev, 'next': next, 'prevy': prevy, 'nexty': nexty, context = {'year': year, 'prev': prev, 'next': next, 'prevy': prevy, 'nexty': nexty,
'files': files, 'dirs': dirs, 'waldata': waldata, 'svxfiles': svxfiles, 'files': files, 'dirs': dirs, 'waldata': waldata, 'svxfiles': svxfiles,
'checked': checked, 'checked': checked,
'trips': trips,
'svxothers': svxothers,
'create': create, 'metadataurl': metadataurl, 'create': create, 'metadataurl': metadataurl,
'complaints': complaints, 'complaints': complaints,
'caveobject': caveobject, 'caveobject': caveobject,

View File

@ -109,31 +109,17 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if psg %}<u>Survey area</u>: <b>{{psg}}</b><br>{% endif %} {% if psg %}<u>Survey area</u>: <b>{{psg}}</b><br>{% endif %}
{% if svxfiles %}<u>Survey files</u>: {% if svxfiles %}<u>Survex files</u>:
{% for svx in svxfiles%} {% for svx in svxfiles %}
<a href="/survexfile/{{svx}}">{{svx}}</a> <a href="/survexfile/{{svx}}">{{svx}}</a>
{% endfor %} {% endfor %}
<br>
<br>
{% endif %} {% endif %}
{% if metadataurl %}<u>Debug</u>: <a href="{{metadataurl}}">json file</a><br> {% endif %}
</span> </span>
<span style="font-family: monospace; font-size: 130%; "> <span style="font-family: monospace; font-size: 130%; ">
<!--
<table style="border: 1px; border-style: hidden;>
{% for d, value in waldata.items %}
<tr style="border-style: hidden;">
<td style="border-style: hidden; padding-right: 3em;">{{d}}</td>
<td> <b>{{value}}</b></td>
</tr>
{% empty %}
<p>&lt;No JSON data here&gt;
{% endfor %}
</table>
-->
</span> </span>
<style> <style>
input {font-family: monospace; font-weight: bold; font-size: 100%; padding: 0.5em; } input {font-family: monospace; font-weight: bold; font-size: 100%; padding: 0.5em; }
@ -210,5 +196,34 @@
</button>{% endif %} </button>{% endif %}
</form> </form>
</div> </div>
<span style="font-family: monospace; font-size: 150%; ">
{% if trips %}<u>Logbook trips</u> on this date:<br>
<span style="font-size: 70%; ">
{% for item in trips %}
{% if item.isLogbookEntry %}&nbsp;&nbsp;&nbsp;&nbsp;<a href="{{item.get_absolute_url}}">{{item.title|safe}}</a><br/>{% endif %}
{% empty %}
<em>None found for this date, bit there should be..</em><br>
{% endfor %}
</span>
{% else %}
<em>No Logbook trips found for this date.</em><br>
{% endif %}
{% if svxothers %}<u>Other survex files</u> on this date:<br>
<span style="font-size: 70%; ">
{% for item in svxothers %}
{% if item.isSurvexBlock %}&nbsp;&nbsp;&nbsp;&nbsp;<a href="/survexfile/{{item.survexfile.path}}">{{item.survexfile.path|safe}}</a><br/>{% endif %}
{% empty %}
<em>None found for this date, bit there should be..</em><br>
{% endfor %}
</span>
{% else %}
<em>No other survex files found for this date.</em><br>
{% endif %}
{% if metadataurl %}<u>Debug</u>:
<span style="font-size: 70%; ">
<a href="{{metadataurl}}">json file</a><br> {% endif %}
</span>
</span>
{% endif %} <!-- not create --> {% endif %} <!-- not create -->
{% endblock %} {% endblock %}