diff options
author | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-05-13 05:34:33 +0100 |
---|---|---|
committer | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-05-13 05:34:33 +0100 |
commit | 832f1f53c6f3bd4e1323df728f8fe974df6f5dc4 (patch) | |
tree | 322ff22fcfaa020cefb78171e37874437460a72a /expo/view_surveys.py | |
parent | a366161a245339072d55581374df396271cabcac (diff) | |
download | troggle-832f1f53c6f3bd4e1323df728f8fe974df6f5dc4.tar.gz troggle-832f1f53c6f3bd4e1323df728f8fe974df6f5dc4.tar.bz2 troggle-832f1f53c6f3bd4e1323df728f8fe974df6f5dc4.zip |
[svn] 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
Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8172 by julian @ 1/17/2009 11:25 PM
Diffstat (limited to 'expo/view_surveys.py')
-rw-r--r-- | expo/view_surveys.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/expo/view_surveys.py b/expo/view_surveys.py new file mode 100644 index 0000000..cd3210b --- /dev/null +++ b/expo/view_surveys.py @@ -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"
\ No newline at end of file |