mirror of
https://expo.survex.com/repositories/expoweb/.git/
synced 2024-11-23 07:41:56 +00:00
[svn r8172] Modifications to allow survey files to be pulled from another server. By providing directory listing and download functions,. which could also be used by tunnel
This commit is contained in:
parent
22b7620253
commit
cbb1acd1b4
44
troggle/expo/view_surveys.py
Normal file
44
troggle/expo/view_surveys.py
Normal file
@ -0,0 +1,44 @@
|
||||
import troggle.settings as settings
|
||||
from django.http import HttpResponse, Http404
|
||||
import os
|
||||
|
||||
def listdir(request, path):
|
||||
try:
|
||||
l = []
|
||||
print settings.FILES, "t", path, "t"
|
||||
root = os.path.join(settings.FILES, path)
|
||||
print root
|
||||
for p in os.listdir(root):
|
||||
if os.path.isdir(os.path.join(root, p)):
|
||||
l.append(p + "/")
|
||||
elif os.path.isfile(os.path.join(root, p)):
|
||||
l.append(p)
|
||||
#Ignore non-files and non-directories
|
||||
return HttpResponse(str(l), mimetype = "text/plain")
|
||||
except:
|
||||
try:
|
||||
return HttpResponse(urllib.urlopen(settings.FILES + "listdir/" + name), mimetype = "text/plain")
|
||||
except:
|
||||
raise Http404
|
||||
|
||||
def upload(request, path):
|
||||
pass
|
||||
|
||||
def download(request, path):
|
||||
try:
|
||||
f = open(os.path.join(settings.FILES, path))
|
||||
except:
|
||||
try:
|
||||
f = urllib.urlopen(settings.FILES + "download/" + path)
|
||||
except:
|
||||
raise Http404
|
||||
return HttpResponse(f.read(), mimetype=getMimeType(path.split(".")[-1]))
|
||||
|
||||
def getMimeType(extension):
|
||||
try:
|
||||
return {"txt": "text/plain",
|
||||
"html": "text/html",
|
||||
}[extension]
|
||||
except:
|
||||
print "unknown file type"
|
||||
return "text/plain"
|
@ -1,5 +1,6 @@
|
||||
import sys
|
||||
import os
|
||||
import urllib
|
||||
import types
|
||||
sys.path.append('C:\\Expo\\expoweb')
|
||||
from troggle import *
|
||||
@ -13,12 +14,21 @@ import csv
|
||||
import re
|
||||
import datetime
|
||||
|
||||
surveytab = open(os.path.join(settings.SURVEYS, "Surveys.csv"))
|
||||
dialect=csv.Sniffer().sniff(surveytab.read())
|
||||
surveytab.seek(0,0)
|
||||
def openFileOrWeb(name):
|
||||
try:
|
||||
f = open(os.path.join(settings.SURVEYS, name))
|
||||
except:
|
||||
f = urllib.urlopen(settings.SURVEYS + name)
|
||||
return f.readlines()
|
||||
|
||||
surveytab = openFileOrWeb("Surveys.csv")
|
||||
|
||||
dialect=csv.Sniffer().sniff(reduce(lambda x, y: x + "\n" + y, surveytab))
|
||||
surveyreader = csv.reader(surveytab,dialect=dialect)
|
||||
print surveyreader
|
||||
headers = surveyreader.next()
|
||||
header = dict(zip(headers, range(len(headers)))) #set up a dictionary where the indexes are header names and the values are column numbers
|
||||
print header
|
||||
|
||||
# test if the expeditions have been added yet
|
||||
if len(models.Expedition.objects.all())==0:
|
||||
@ -27,9 +37,10 @@ if len(models.Expedition.objects.all())==0:
|
||||
models.ScannedImage.objects.all().delete()
|
||||
models.Survey.objects.all().delete()
|
||||
for survey in surveyreader:
|
||||
print type(survey), survey
|
||||
walletNumberLetter = re.match(r'(?P<number>\d*)(?P<letter>[a-zA-Z]*)',survey[header['Survey Number']]) #I hate this, but some surveys have a letter eg 2000#34a. This line deals with that.
|
||||
# print walletNumberLetter.groups()
|
||||
|
||||
|
||||
surveyobj = models.Survey(
|
||||
expedition = models.Expedition.objects.filter(year=survey[header['Year']])[0],
|
||||
wallet_number = walletNumberLetter.group('number'),
|
||||
@ -43,7 +54,7 @@ for survey in surveyreader:
|
||||
pass
|
||||
surveyobj.save()
|
||||
print "added survey " + survey[header['Year']] + "#" + surveyobj.wallet_number
|
||||
|
||||
|
||||
# add survey scans
|
||||
def parseSurveyScans(year):
|
||||
yearPath=os.path.join(settings.SURVEYS, year.year)
|
||||
|
@ -1,5 +1,6 @@
|
||||
from django.conf.urls.defaults import *
|
||||
from expo.views import *
|
||||
import expo.view_surveys as view_surveys
|
||||
import troggle.settings as settings
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
@ -12,7 +13,7 @@ urlpatterns = patterns('',
|
||||
(r'^cave/(?P<cave_id>[^/]+)/?(?P<ent_letter>[^/])$', ent),
|
||||
#(r'^cave/(?P<cave_id>[^/]+)/edit/$', edit_cave),
|
||||
(r'^cavesearch', caveSearch),
|
||||
|
||||
|
||||
(r'^survex/(?P<survex_file>.*)\.index$', index),
|
||||
(r'^survex/(?P<survex_file>.*)\.svx$', svx),
|
||||
(r'^survex/(?P<survex_file>.*)\.3d$', threed),
|
||||
@ -36,6 +37,10 @@ urlpatterns = patterns('',
|
||||
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
|
||||
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
|
||||
|
||||
(r'^survey_files/listdir/(?P<path>.*)$', view_surveys.listdir),
|
||||
(r'^survey_files/download/(?P<path>.*)$', view_surveys.download),
|
||||
#(r'^survey_files/upload/(?P<path>.*)$', view_surveys.upload),
|
||||
|
||||
(r'^survey_scans/(?P<path>.*)$', 'django.views.static.serve',
|
||||
{'document_root': settings.SURVEYS, 'show_indexes':True}),
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user