From 24d90bae752dfc5d51cf038d3a5d4b3858765e9f Mon Sep 17 00:00:00 2001 From: goatchurch Date: Mon, 14 Sep 2009 22:52:46 +0100 Subject: make 2008 logbook correctly parse --- core/view_surveys.py | 62 +++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 27 deletions(-) (limited to 'core/view_surveys.py') diff --git a/core/view_surveys.py b/core/view_surveys.py index fc93a7e..66aa1ed 100644 --- a/core/view_surveys.py +++ b/core/view_surveys.py @@ -5,6 +5,7 @@ from django.http import HttpResponse, Http404 import os, stat import re from troggle.core.models import SurvexScansFolder, SurvexScanSingle, SurvexBlock, TunnelFile +import parsers.surveys # inline fileabstraction into here if it's not going to be useful anywhere else # keep things simple and ignore exceptions everywhere for now @@ -182,43 +183,50 @@ def tunneldata(request): tunnelfiles = TunnelFile.objects.all() return render_to_response('tunnelfiles.html', { 'tunnelfiles':tunnelfiles, 'settings': settings }) + 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") - # just output the file - if not request.POST: - return HttpResponse(content=open(tfile), mimetype="text/plain") +def tunnelfileupload(request, path): + tunnelfile = TunnelFile.objects.get(tunnelpath=path) + tfile = os.path.join(settings.TUNNEL_DATA, tunnelfile.tunnelpath) project, user, password, tunnelversion = request.POST["tunnelproject"], request.POST["tunneluser"], request.POST["tunnelpassword"], request.POST["tunnelversion"] print (project, user, tunnelversion) - for uploadedfile in request.FILES.values(): - if uploadedfile.field_name != "sketch": - return HttpResponse(content="Error: non-sketch file uploaded", mimetype="text/plain") - if uploadedfile.content_type != "text/plain": - return HttpResponse(content="Error: non-plain content type", mimetype="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") - - orgsize = tunnelfile.filesize # = os.stat(tfile)[stat.ST_SIZE] - - ttext = uploadedfile.read() - - # could check that the user and projects agree here + + + assert len(request.FILES.values()) == 1, "only one file to upload" + + uploadedfile = request.FILES.values()[0] - fout = open(tfile, "w") - fout.write(ttext) - fout.close() + if uploadedfile.field_name != "sketch": + return HttpResponse(content="Error: non-sketch file uploaded", mimetype="text/plain") + if uploadedfile.content_type != "text/plain": + return HttpResponse(content="Error: non-plain content type", mimetype="text/plain") - # redo its settings of - tunnelfile.filesize = os.stat(tfile)[stat.ST_SIZE] - tunnelfile.save() + # could use this to add new files + if os.path.split(path)[1] != uploadedfile.name: + return HttpResponse(content="Error: name disagrees", mimetype="text/plain") + + orgsize = tunnelfile.filesize # = os.stat(tfile)[stat.ST_SIZE] - uploadedfile.close() - message = "File size %d overwritten with size %d" % (orgsize, tunnelfile.filesize) - return HttpResponse(content=message, mimetype="text/plain") + ttext = uploadedfile.read() + + # could check that the user and projects agree here + + fout = open(tfile, "w") + fout.write(ttext) + fout.close() + + # redo its settings of + parsers.surveys.SetTunnelfileInfo(tunnelfile) + tunnelfile.save() + + uploadedfile.close() + message = "File size %d overwritten with size %d" % (orgsize, tunnelfile.filesize) + return HttpResponse(content=message, mimetype="text/plain") -- cgit v1.2.3