I wanted to share some information with the list here re: my tests of tramline with django. Here's some information about my setup:<br><br>Front end apache server with patched mod_python proxy-ing a django/mod_python instance on another server. Here's the relavant tramline
httpd.conf:<br><br><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">LoadModule python_module modules/mod_python.so</span><br><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">PythonInputFilter tramline.core::inputfilter TRAMLINE_INPUT</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">PythonOutputFilter tramline.core::outputfilter TRAMLINE_OUTPUT</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">SetInputFilter TRAMLINE_INPUT
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">SetOutputFilter TRAMLINE_OUTPUT</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
PythonOption tramline_path /opt/tramline/var/data</span><br><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"></span>
<span style="font-family: courier new,monospace;">RewriteEngine On<br><br>## serve some static media from this apache server ##<br style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">
</span><span style="font-family: courier new,monospace;">RewriteRule ^/static/(.*) - [L]<br><br>## pass all other requests to django server ##<br style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">
RewriteRule ^/(.*) <a href="http://django-server/$1">http://django-server/$1</a> [P,L</span>]<br></div><br><br>Here's my django model for referencing a tramline file:<br><br><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">
class TramlineFile(models.Model):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> name = models.CharField(maxlength=200)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> type = models.ForeignKey(FileType)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> tramline_id = models.CharField
(maxlength=20)</span><br></div><br>Here's my django 'view' code for uploading a file:<br><br><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">def upload(request):</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> '''</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Handle file upload</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> '''<br> ## placeholder hack until file types are in db ##<br style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">
file_type = FileType.objects.get(pk=1)<br><br> ## save each tramline file object to the db ##<br style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"> for file in
request.FILES.values():</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> tlf = TramlineFile(name=file["filename"], type=file_type, tramline_id=file["content"].strip())
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> tlf.save()<br><br> ## build redirect response ##<br style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">
response = HttpResponseRedirect("/files/")<br><br> ## set special tramline header ##<br style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"> response["tramline_ok"] = "True"
<br><br style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"> return response</span><br></div><br>Here's my django 'view' code for downloading a file:<br><br>
<div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">def get_file(request, file_id):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> '''
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Handle file download</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
'''<br><br> ## get tramline file object from db ##<br style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"> file = get_object_or_404(TramlineFile, pk=file_id)
<br><br style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"> ## placeholder hack until we are can get content-type from the db ##</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ext = file.name.rsplit('.', 1)[-1].lower()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if ext in
EXTS.keys():</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> contentType = EXTS[ext]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
else:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> contentType = "text/plain"<br><br> ## send file id as the response body, and use appropriate content-type ##
<br style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"> response = HttpResponse(file.tramline_id, contentType)<br><br> ## set header for tramline ##<br style="font-family: courier new,monospace;">
</span><span style="font-family: courier new,monospace;"> response["tramline_file"] = "True"<br><br style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">
return response</span><br></div><br><br>Tramline's performance appears to be very good. I am having trouble, though, with django's parsing performance of the POST data when uploading very large (600+) numbers of files in one post with jupload (
<a href="http://www.jupload.biz/">http://www.jupload.biz/</a>). (Even with tramline, the size of the request django gets with these large uploads is ~3MB. Part of that could be the extra attributes that jupload sends along with each file as form data.) I'm going to look at handling the raw post data with some custom code and I'll post my results here.
<br><br>The end result of this so far: Tramline works well with django and was very simple to integrate.<br><br>Also, maybe I missed it, but does tramline include the file size metadata in the post? Is anyone else interested in a patch to provide this if it doesn't already?
<br><br>Chad<br>