Beispiel #1
0
def edit_file(request, id):
    uploadedfile = get_object_or_404(UploadedFile, pk=id)
    if request.user == uploadedfile.user or request.user.is_superuser:
        if request.method == 'POST':
            form = UploadedFileForm(request.POST, request.FILES, instance=uploadedfile)
            if form.is_valid():
                #m = magic.open(magic.MAGIC_MIME)
                #m.load()
                uploaded_file = form.save(commit=False)
                #uploaded_file.user = request.user
                if 'file' in request.FILES:
                    uploaded_file.filename = request.FILES['file'].name
                    uploaded_file.content_type = request.FILES['file'].content_type
                #original_filename = "{root}originals/{filename}".format(
                #    root=settings.FILE_SERVE_ROOT,
                #    filename=uploaded_file.file)
                #original_filename = "%soriginals/%s" % (settings.FILE_SERVE_ROOT, uploaded_file.file)
                #import pdb; pdb.set_trace()
                #uploaded_file.content_type = magic.Magic(mime=True).from_file(original_filename)
                #uploaded_file.content_type = m.file(original_filename)
                # FIXME: Use one of the above
                uploaded_file.save()
                return HttpResponseRedirect('/files')
        else:
            form = UploadedFileForm(instance=uploadedfile)
        return render_to_response('vault/new_file.html', {'form': form}, context_instance=RequestContext(request))
    else:
        raise Http403
Beispiel #2
0
def new_file(request):
    if request.method == 'POST':
        form = UploadedFileForm(request.POST, request.FILES)
        if form.is_valid():
            uploaded_file = form.save(commit=False)
            uploaded_file.user = request.user
            uploaded_file.filename = request.FILES['file'].name
            #original_filename = "{root}originals/{filename}".format(
            #    root=settings.FILE_SERVE_ROOT,
            #    filename=uploaded_file.file)
            #original_filename = "%soriginals/%s" % (settings.FILE_SERVE_ROOT, uploaded_file.file)
            #import pdb; pdb.set_trace()
            #uploaded_file.content_type = magic.Magic(mime=True).from_file(original_filename)
            #uploaded_file.content_type = m.file(original_filename)
            # FIXME: Use one of the above
            uploaded_file.content_type = request.FILES['file'].content_type
            uploaded_file.save()
            return HttpResponseRedirect('/files')
    else:
        uploadedfile = UploadedFile()
        form = UploadedFileForm(instance=uploadedfile)
    return render_to_response('vault/new_file.html', {'form': form}, context_instance=RequestContext(request))