forked from expo/troggle
able to save sketches up from tunnel
This commit is contained in:
parent
12cf3a6d53
commit
517d291636
@ -173,5 +173,9 @@ class TunnelFile(models.Model):
|
||||
survexscans = models.ManyToManyField("SurvexScanSingle")
|
||||
survexblocks = models.ManyToManyField("SurvexBlock")
|
||||
tunnelcontains = models.ManyToManyField("TunnelFile") # case when its a frame type
|
||||
filesize = models.IntegerField(default=0)
|
||||
npaths = models.IntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
ordering = ('tunnelpath',)
|
||||
|
@ -2,7 +2,7 @@ from django.conf import settings
|
||||
import fileAbstraction
|
||||
from django.shortcuts import render_to_response
|
||||
from django.http import HttpResponse, Http404
|
||||
import os
|
||||
import os, stat
|
||||
import re
|
||||
from troggle.core.models import SurvexScansFolder, SurvexScanSingle, SurvexBlock, TunnelFile
|
||||
|
||||
@ -181,4 +181,45 @@ def surveyscansfolders(request):
|
||||
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)
|
||||
|
||||
# just output the file
|
||||
if not request.POST:
|
||||
return HttpResponse(content=open(tfile), mimetype="text/plain")
|
||||
|
||||
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
|
||||
|
||||
fout = open(tfile, "w")
|
||||
fout.write(ttext)
|
||||
fout.close()
|
||||
|
||||
# redo its settings of
|
||||
tunnelfile.filesize = os.stat(tfile)[stat.ST_SIZE]
|
||||
tunnelfile.save()
|
||||
|
||||
uploadedfile.close()
|
||||
message = "File size %d overwritten with size %d" % (orgsize, tunnelfile.filesize)
|
||||
return HttpResponse(content=message, mimetype="text/plain")
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -77,7 +77,7 @@ def parse_descriptions():
|
||||
|
||||
def import_tunnelfiles():
|
||||
import parsers.surveys
|
||||
parsers.surveys.LoadTunnelFiles(settings.TUNNEL_DATA)
|
||||
parsers.surveys.LoadTunnelFiles()
|
||||
|
||||
|
||||
def reset():
|
||||
|
@ -1,4 +1,4 @@
|
||||
import sys, os, types, logging
|
||||
import sys, os, types, logging, stat
|
||||
#sys.path.append('C:\\Expo\\expoweb')
|
||||
#from troggle import *
|
||||
#os.environ['DJANGO_SETTINGS_MODULE']='troggle.settings'
|
||||
@ -204,7 +204,30 @@ def LoadListScans(surveyscansdir):
|
||||
|
||||
|
||||
|
||||
def LoadTunnelFiles(tunneldatadir):
|
||||
def SetTunnelfileInfo(tunnelfile):
|
||||
ff = os.path.join(settings.TUNNEL_DATA, tunnelfile.tunnelpath)
|
||||
tunnelfile.filesize = os.stat(ff)[stat.ST_SIZE]
|
||||
fin = open(ff)
|
||||
ttext = fin.read()
|
||||
fin.close()
|
||||
|
||||
mtype = re.search("<(fontcolours|sketch)", ttext)
|
||||
assert mtype, ff
|
||||
tunnelfile.bfontcolours = (mtype.group(1)=="fontcolours")
|
||||
tunnelfile.npaths = len(re.findall("<skpath", ttext))
|
||||
tunnelfile.save()
|
||||
|
||||
# <tunnelxml tunnelversion="version2009-06-21 Matienzo" tunnelproject="ireby" tunneluser="goatchurch" tunneldate="2009-06-29 23:22:17">
|
||||
# <pcarea area_signal="frame" sfscaledown="12.282584" sfrotatedeg="-90.76982" sfxtrans="11.676667377221136" sfytrans="-15.677173422877454" sfsketch="204description/scans/plan(38).png" sfstyle="" nodeconnzsetrelative="0.0">
|
||||
print tunnelfile.tunnelpath, re.findall('<pcarea area_signal="frame".*?sfsketch="([^"]*)" sfstyle="([^"]*)"', ttext)
|
||||
# npaths = models.IntegerField()
|
||||
# survexscans = models.ManyToManyField("SurvexScanSingle")
|
||||
# survexblocks = models.ManyToManyField("SurvexBlock")
|
||||
# tunnelcontains = models.ManyToManyField("TunnelFile") # case when its a frame type
|
||||
|
||||
|
||||
def LoadTunnelFiles():
|
||||
tunneldatadir = settings.TUNNEL_DATA
|
||||
TunnelFile.objects.all().delete()
|
||||
tunneldirs = [ "" ]
|
||||
while tunneldirs:
|
||||
@ -217,16 +240,10 @@ def LoadTunnelFiles(tunneldatadir):
|
||||
if os.path.isdir(ff):
|
||||
tunneldirs.append(lf)
|
||||
elif f[-4:] == ".xml":
|
||||
fin = open(ff)
|
||||
mtype = re.search("<(fontcolours|sketch)", fin.read(200))
|
||||
assert mtype, lf
|
||||
fin.close()
|
||||
tunnelfile = TunnelFile(tunnelpath=lf, bfontcolours=(mtype.group(1)=="fontcolours"))
|
||||
tunnelfile = TunnelFile(tunnelpath=lf)
|
||||
tunnelfile.save()
|
||||
SetTunnelfileInfo(tunnelfile)
|
||||
|
||||
|
||||
# survexscans = models.ManyToManyField("SurvexScanSingle")
|
||||
# survexblocks = models.ManyToManyField("SurvexBlock")
|
||||
# tunnelcontains = models.ManyToManyField("TunnelFile") # case when its a frame type
|
||||
|
||||
|
||||
|
@ -8,11 +8,15 @@
|
||||
|
||||
<h3>All Tunnel files</h3>
|
||||
<table>
|
||||
<tr><th>File</th><th>Font</th><th>Frame</th><th>SurvexBlocks</th><th>Size</th></tr>
|
||||
<tr><th>File</th><th>Font</th><th>Frame</th><th>SurvexBlocks</th><th>Size</th><th>Paths</td></tr>
|
||||
{% for tunnelfile in tunnelfiles %}
|
||||
<tr>
|
||||
<td>{{tunnelfile.tunnelpath}}</td>
|
||||
<td><a href="{% url tunnelfile tunnelfile.tunnelpath %}">{{tunnelfile.tunnelpath}}</a></td>
|
||||
<td>{{tunnelfile.bfontcolours}}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>{{tunnelfile.filesize}}</td>
|
||||
<td>{{tunnelfile.npaths}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
3
urls.py
3
urls.py
@ -108,7 +108,10 @@ urlpatterns = patterns('',
|
||||
url(r'^survey_scans/(?P<path>[^/]+)/$', view_surveys.surveyscansfolder, name="surveyscansfolder"),
|
||||
url(r'^survey_scans/(?P<path>[^/]+)/(?P<file>[^/]+(?:png|jpg))$',
|
||||
view_surveys.surveyscansingle, name="surveyscansingle"),
|
||||
|
||||
url(r'^tunneldata/$', view_surveys.tunneldata, name="tunneldata"),
|
||||
url(r'^tunneldataraw/(?P<path>.+?\.xml)$', view_surveys.tunnelfile, name="tunnelfile"),
|
||||
#url(r'^tunneldatainfo/(?P<path>.+?\.xml)$', view_surveys.tunnelfileinfo, name="tunnelfileinfo"),
|
||||
|
||||
(r'^photos/(?P<path>.*)$', 'django.views.static.serve',
|
||||
{'document_root': settings.PHOTOS_ROOT, 'show_indexes':True}),
|
||||
|
Loading…
Reference in New Issue
Block a user