Files @ 69ff8e703a8f
Branch filter:

Location: website/www/conservancy/apps/ccs_upload/views.py

bsturmfels
Add prototype CCS upload feature.
import os
import random

from django.http import HttpResponse
from django.shortcuts import render

CCS_UPLOAD_PATH = '/tmp/'


def upload(request):
    if request.method == 'POST':
        handle_uploaded_file(request.FILES['file'])
        return HttpResponse('Uploaded!')
    else:
        return render(request, 'ccs_upload/upload.html')
    return HttpResponse('Done')


def handle_uploaded_file(f):
    filename = '{hash:x} {name}'.format(hash=random.getrandbits(32), name=f.name)
    path = os.path.join(CCS_UPLOAD_PATH, filename)
    with open(path, 'wb+') as destination:
        for chunk in f.chunks():
            destination.write(chunk)