[Tramline-dev] Django & Tramline

Chad Maine chad.maine at gmail.com
Tue Dec 26 15:40:08 CET 2006


I wanted to share some information with the list here re: my tests of
tramline with django.  Here's some information about my setup:

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:

LoadModule python_module modules/mod_python.so

PythonInputFilter tramline.core::inputfilter TRAMLINE_INPUT
PythonOutputFilter tramline.core::outputfilter TRAMLINE_OUTPUT
SetInputFilter TRAMLINE_INPUT
SetOutputFilter TRAMLINE_OUTPUT
PythonOption tramline_path /opt/tramline/var/data

RewriteEngine On

## serve some static media from this apache server ##
RewriteRule     ^/static/(.*)   -       [L]

## pass all other requests to django server ##
RewriteRule     ^/(.*)  http://django-server/$1 [P,L]


Here's my django model for referencing a tramline file:

class TramlineFile(models.Model):
    name = models.CharField(maxlength=200)
    type = models.ForeignKey(FileType)
    tramline_id = models.CharField(maxlength=20)

Here's my django 'view' code for uploading a file:

def upload(request):
    '''
    Handle file upload
    '''
    ## placeholder hack until file types are in db ##
    file_type = FileType.objects.get(pk=1)

    ## save each tramline file object to the db ##
    for file in request.FILES.values():
        tlf = TramlineFile(name=file["filename"], type=file_type,
tramline_id=file["content"].strip())
        tlf.save()

    ## build redirect response ##
    response = HttpResponseRedirect("/files/")

    ## set special tramline header ##
    response["tramline_ok"] = "True"

    return response

Here's my django 'view' code for downloading a file:

def get_file(request, file_id):
    '''
    Handle file download
    '''

    ## get tramline file object from db ##
    file = get_object_or_404(TramlineFile, pk=file_id)

    ## placeholder hack until we are can get content-type from the db ##
    ext = file.name.rsplit('.', 1)[-1].lower()
    if ext in EXTS.keys():
        contentType = EXTS[ext]
    else:
        contentType = "text/plain"

    ## send file id as the response body, and use appropriate content-type
##
    response = HttpResponse(file.tramline_id, contentType)

    ## set header for tramline ##
    response["tramline_file"] = "True"

    return response


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 (
http://www.jupload.biz/).  (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.

The end result of this so far:  Tramline works well with django and was very
simple to integrate.

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?

Chad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codespeak.net/pipermail/tramline-dev/attachments/20061226/85f836c9/attachment-0001.htm 


More information about the Tramline-dev mailing list