From e6fa54d0e5ecbbe9811a19df5c42a1927f893b48 Mon Sep 17 00:00:00 2001 From: Sam Wenham Date: Sun, 24 Feb 2019 16:46:02 +0000 Subject: [PATCH] Fix survey scans Remove the assert for folders in survey wallets, this does mean currently they will be ignored by troggle. --- core/view_surveys.py | 21 +++++++++++---------- parsers/surveys.py | 4 ++-- urls.py | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/core/view_surveys.py b/core/view_surveys.py index a6df780..0e958c7 100644 --- a/core/view_surveys.py +++ b/core/view_surveys.py @@ -23,7 +23,7 @@ def getMimeType(extension): def listdir(request, path): #try: - return HttpResponse(fileAbstraction.listdir(path), mimetype = "text/plain") + return HttpResponse(fileAbstraction.listdir(path), content_type="text/plain") #except: # raise Http404 @@ -33,7 +33,7 @@ def upload(request, path): def download(request, path): #try: - return HttpResponse(fileAbstraction.readFile(path), mimetype=getMimeType(path.split(".")[-1])) + return HttpResponse(fileAbstraction.readFile(path), content_type=getMimeType(path.split(".")[-1])) #except: # raise Http404 @@ -46,6 +46,7 @@ extmimetypes = {".txt": "text/plain", ".html": "text/html", ".png": "image/png", ".jpg": "image/jpeg", + ".jpeg": "image/jpeg", } # dead @@ -93,9 +94,9 @@ def jgtfile(request, f): fin = open(fp) ftext = fin.read() fin.close() - return HttpResponse(ftext, mimetype=mimetype) + return HttpResponse(ftext, content_type=mimetype) - return HttpResponse("unknown file::%s::" % f, mimetype = "text/plain") + return HttpResponse("unknown file::%s::" % f, content_type = "text/plain") def UniqueFile(fname): @@ -171,7 +172,7 @@ def surveyscansfolder(request, path): def surveyscansingle(request, path, file): survexscansfolder = SurvexScansFolder.objects.get(walletname=path) survexscansingle = SurvexScanSingle.objects.get(survexscansfolder=survexscansfolder, name=file) - return HttpResponse(content=open(survexscansingle.ffile), mimetype="image/png") + return HttpResponse(content=open(survexscansingle.ffile), content_type=getMimeType(path.split(".")[-1])) #return render_to_response('survexscansfolder.html', { 'survexscansfolder':survexscansfolder, 'settings': settings }) def surveyscansfolders(request): @@ -187,7 +188,7 @@ def tunneldata(request): def tunnelfile(request, path): tunnelfile = TunnelFile.objects.get(tunnelpath=path) tfile = os.path.join(settings.TUNNEL_DATA, tunnelfile.tunnelpath) - return HttpResponse(content=open(tfile), mimetype="text/plain") + return HttpResponse(content=open(tfile), content_type="text/plain") def tunnelfileupload(request, path): tunnelfile = TunnelFile.objects.get(tunnelpath=path) @@ -202,13 +203,13 @@ def tunnelfileupload(request, path): uploadedfile = request.FILES.values()[0] if uploadedfile.field_name != "sketch": - return HttpResponse(content="Error: non-sketch file uploaded", mimetype="text/plain") + return HttpResponse(content="Error: non-sketch file uploaded", content_type="text/plain") if uploadedfile.content_type != "text/plain": - return HttpResponse(content="Error: non-plain content type", mimetype="text/plain") + return HttpResponse(content="Error: non-plain content type", content_type="text/plain") # could use this to add new files if os.path.split(path)[1] != uploadedfile.name: - return HttpResponse(content="Error: name disagrees", mimetype="text/plain") + return HttpResponse(content="Error: name disagrees", content_type="text/plain") orgsize = tunnelfile.filesize # = os.stat(tfile)[stat.ST_SIZE] @@ -226,7 +227,7 @@ def tunnelfileupload(request, path): uploadedfile.close() message = "File size %d overwritten with size %d" % (orgsize, tunnelfile.filesize) - return HttpResponse(content=message, mimetype="text/plain") + return HttpResponse(content=message, content_type="text/plain") diff --git a/parsers/surveys.py b/parsers/surveys.py index 02b06f5..29de15c 100644 --- a/parsers/surveys.py +++ b/parsers/surveys.py @@ -147,7 +147,7 @@ def parseSurveys(logfile=None): except (IOError, OSError): print("Survey CSV not found..") pass - + for expedition in Expedition.objects.filter(year__gte=2000): #expos since 2000, because paths and filenames were nonstandard before then parseSurveyScans(expedition) @@ -189,7 +189,7 @@ def LoadListScansFile(survexscansfolder): gld.append((fyf, ffyf, fisdiryf)) for (fyf, ffyf, fisdiryf) in gld: - assert not fisdiryf, ffyf + #assert not fisdiryf, ffyf if re.search(r"\.(?:png|jpg|jpeg)(?i)$", fyf): survexscansingle = SurvexScanSingle(ffile=ffyf, name=fyf, survexscansfolder=survexscansfolder) survexscansingle.save() diff --git a/urls.py b/urls.py index e00dee8..77b2bd2 100644 --- a/urls.py +++ b/urls.py @@ -129,7 +129,7 @@ actualurlpatterns = patterns('', #(r'^survey_scans/(?P.*)$', 'django.views.static.serve', {'document_root': settings.SURVEY_SCANS, 'show_indexes':True}), url(r'^survey_scans/$', view_surveys.surveyscansfolders, name="surveyscansfolders"), url(r'^survey_scans/(?P[^/]+)/$', view_surveys.surveyscansfolder, name="surveyscansfolder"), - url(r'^survey_scans/(?P[^/]+)/(?P[^/]+(?:png|jpg))$', + url(r'^survey_scans/(?P[^/]+)/(?P[^/]+(?:png|jpg|jpeg))$', view_surveys.surveyscansingle, name="surveyscansingle"), url(r'^tunneldata/$', view_surveys.tunneldata, name="tunneldata"),