summaryrefslogtreecommitdiffstats
path: root/core/views/scans.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2021-05-03 20:36:29 +0100
committerPhilip Sargent <philip.sargent@klebos.com>2021-05-03 20:36:29 +0100
commitfd95bb81985d51b8a231131aead9b8bc37b26a8d (patch)
tree5a83e5643c363a376f76dcfedc71b765fd6321d5 /core/views/scans.py
parent9b9f6720e079669fd884d83f6b69833e20d03ff7 (diff)
downloadtroggle-fd95bb81985d51b8a231131aead9b8bc37b26a8d.tar.gz
troggle-fd95bb81985d51b8a231131aead9b8bc37b26a8d.tar.bz2
troggle-fd95bb81985d51b8a231131aead9b8bc37b26a8d.zip
split surveys->scans + drawings
Diffstat (limited to 'core/views/scans.py')
-rw-r--r--core/views/scans.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/core/views/scans.py b/core/views/scans.py
new file mode 100644
index 0000000..3acdbae
--- /dev/null
+++ b/core/views/scans.py
@@ -0,0 +1,47 @@
+import os, stat
+import re
+from pathlib import Path
+from urllib.parse import urljoin, unquote as urlunquote
+from urllib.request import urlopen
+
+from django.conf import settings
+from django.shortcuts import render
+from django.http import HttpResponse
+
+from troggle.core.models.survex import Wallet, SingleScan
+from troggle.core.views.expo import getmimetype
+#import parsers.surveys
+
+'''one of these views serves files as binary blobs, and simply set the mime type based on the file extension,
+as does the urls.py dispatcher which sends them here. Here they should actually have the filetype checked
+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:
+ wallet = Wallet.objects.get(walletname=urlunquote(path))
+ return render(request, 'wallet.html', { 'wallet':wallet, 'settings': settings })
+ except:
+ message = f'Scan folder error or not found \'{path}\' .'
+ return render(request, 'errors/generic.html', {'message': message})
+
+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)))
+ 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}\'.'
+ return render(request, 'errors/generic.html', {'message': message})
+
+
+def allwallets(request):
+ manywallets = Wallet.objects.all()
+ return render(request, 'manywallets.html', { 'manywallets':manywallets, 'settings': settings })