From 8245ee103e3569888145f8781b4405ee9fa657db Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 21 Jul 2022 10:32:11 +0300 Subject: [PATCH] wallets for just one cave --- core/views/scans.py | 18 +++++++++++++++++- templates/cavewallets.html | 37 +++++++++++++++++++++++++++++++++++++ templates/manywallets.html | 2 +- urls.py | 10 +++++----- 4 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 templates/cavewallets.html diff --git a/core/views/scans.py b/core/views/scans.py index 097c69f..8ecec0a 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -9,6 +9,7 @@ from django.shortcuts import render from django.http import HttpResponse from troggle.core.models.survex import Wallet, SingleScan +from troggle.core.models.caves import GetCaveLookup from troggle.core.views.expo import getmimetype #import parsers.surveys @@ -47,10 +48,11 @@ def walletindex(request, path): def scansingle(request, path, file): '''sends a single binary file to the user for display - browser decides how using mimetype ''' + try: wallet = Wallet.objects.get(walletname=urlunquote(path)) singlescan = SingleScan.objects.get(wallet=wallet, name=file) - # print(" - scansingle {}:{}:{}:".format(path, file, getmimetype(file))) + print(" - scansingle {}:{}:{}:".format(path, file, getmimetype(file))) return HttpResponse(content=open(singlescan.ffile,"rb"), content_type=getmimetype(file)) # any type of image except: message = f'Scan folder or scan item error or not found \'{path}\' and \'{file}\'.' @@ -66,3 +68,17 @@ def allwallets(request): manywallets = Wallet.objects.all() # manywallets = Wallet.objects.all().prefetch_related('singlescan') fails as the link is defined on 'singlescan' not on 'wallet' return render(request, 'manywallets.html', { 'manywallets':manywallets, 'settings': settings }) + +def cavewallets(request, cave_id): + '''Returns all the wallets for just one cave, + ''' + Gcavelookup = GetCaveLookup() + if cave_id in Gcavelookup: + cave = Gcavelookup[cave_id] + else: + return render(request,'errors/badslug.html', {'badslug': cave_id}) + + print(f'cavewallets {cave_id=} {cave=}') + + manywallets = Wallet.objects.filter(survexblock__survexfile__cave=cave) + return render(request, 'cavewallets.html', { 'manywallets':manywallets, 'settings': settings }) diff --git a/templates/cavewallets.html b/templates/cavewallets.html new file mode 100644 index 0000000..670ce51 --- /dev/null +++ b/templates/cavewallets.html @@ -0,0 +1,37 @@ +{% extends "base.html" %} + +{% block title %}All Survey scans folders (wallets){% endblock %} + +{% block content %} + +

Survey scans folders (wallets) for a specific cave

+

Each wallet contains the scanned original in-cave survey notes and sketches of +plans and elevations. It also contains scans of centre-line survex output on which +hand-drawn passage sections are drawn. These hand-drawn passages will eventually be +traced to produce Tunnel or Therion drawings and eventually the final complete cave survey. + + + + +{% for scanswallet in manywallets %} + + + + + + +{% endfor %} +
Scans folderFilesSurvex blocksCave
{{scanswallet.walletname}}{{scanswallet.singlescan_set.all|length}} + {% for survexblock in scanswallet.survexblock_set.all %} + {{survexblock}} + {% endfor %} + + {% for survexblock in scanswallet.survexblock_set.all %} + {% ifchanged survexblock.survexfile.cave %} + /{{survexblock.survexfile.cave.slug}} + {% endifchanged %} + + {% endfor %} +
+ +{% endblock %} \ No newline at end of file diff --git a/templates/manywallets.html b/templates/manywallets.html index 46dd302..7fc04cb 100644 --- a/templates/manywallets.html +++ b/templates/manywallets.html @@ -27,7 +27,7 @@ see https://docs.djangoproject.com/en/3.2/ref/models/querysets/#prefetch-related {% for survexblock in scanswallet.survexblock_set.all %} {% ifchanged survexblock.survexfile.cave %} - /{{survexblock.survexfile.cave.slug}} + /{{survexblock.survexfile.cave.slug}} {% endifchanged %} {% endfor %} diff --git a/urls.py b/urls.py index 56c6fa5..e02c4f0 100644 --- a/urls.py +++ b/urls.py @@ -8,7 +8,7 @@ from django.contrib import auth from django.urls import path, reverse, resolve from troggle.core.views import statistics, survex -from troggle.core.views.scans import scansingle, allwallets +from troggle.core.views.scans import scansingle, allwallets, cavewallets from troggle.core.views.drawings import dwgallfiles, dwgfilesingle from troggle.core.views.uploads import dwgupload, scanupload, photoupload from troggle.core.views.other import troggle404, frontpage, todos, controlpanel, frontpage @@ -133,8 +133,7 @@ trogglepatterns = [ re_path(r'^(?P[^/]+)_cave_edit/$', edit_cave, name="edit_cave"), # edit_cave needed by cave.html template for url matching re_path(r'^(.*)_edit$', editexpopage, name="editexpopage"), re_path(r'^(?P\d\d\d\d)(?P.*)$', cavepage, name="cavepage"), # shorthand /1623/264 or 1623/161/top.htm - # Note that urls eg '/1623/161/l/rl89a.htm' are handled by cavepage which redirects them to 'expopage' - # Note that _edit$ for a cave description page in a subfolder e.g. /1623/204/204.html_edit gets caught here and breaks with 404 + # Note that urls eg '/1623/161/l/rl89a.htm' are handled by cavepage which redirects them to 'expopage' # Note that _edit$ for a cave description page in a subfolder e.g. /1623/204/204.html_edit gets caught here and breaks with 404 # Entrances re_path(r'^cave/entrance/([^/]+)/?$', caveEntrance), # lists all entrances !!!BAD, local links fail @@ -168,7 +167,8 @@ trogglepatterns = [ # The survey scans in the wallets. This short-cuts SCANS_URL which is not actually used anywhere! path('survey_scans/', allwallets, name="allwallets"), path('survey_scans//', scanupload, name="singlewallet"), # replaced singlewallet() - path('survey_scans//', scansingle, name="scansingle"), + path('survey_scans//', scansingle, name="scansingle"), # works, but html href goes direct to /expofiles/ too + re_path(r'^cave/scans/(?P[^/]+)$', cavewallets, name="cavewallets"), # like allwallets, but for just one cave # The tunnel and therion drawings files pages path('dwgfiles', dwgallfiles, name="dwgallfiles"), @@ -176,7 +176,7 @@ trogglepatterns = [ path('dwgdataraw/', dwgfilesingle, name="dwgfilesingle"), # QMs pages - must precede other /caves pages? - re_path(r'^cave/qms/([^/]+)/?$', caveQMs, name="caveQMs"), # Fixed. July 2022 + re_path(r'^cave/qms/([^/]+)/?$', caveQMs, name="caveQMs"), re_path(r'^cave/qms/(?P[^/]+)/(?P\d\d\d\d)-(?P\d*)(?P[ABCDXV\?]?)-?(?P[a-zA-Z]+.*)?$', qm, name="qm"), # Dogs breakfast # the resolution of a QM uses several fields together, there is no clean slug field. Artefact of history.