Esempio n. 1
0
def upload_file(request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            instance = FileUpload(uploaded_by=request.user, file_type=FileUpload.SYLLABUS, file_field=request.FILES['file'])
            instance.save()
            return HttpResponse(instance.file_field.read())
        else:
            return HttpResponse("hahahahhahaha")
    else:
        form = UploadFileForm()
        return render_to_response('repository/upload.html', {'form': form}, context_instance=RequestContext(request))
Esempio n. 2
0
def index_view(request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)  #form
        if form.is_valid():
            #save the file into the database
            fileupload = FileUpload(filename=request.FILES['filename'],
                                    email=request.POST['email'])
            fileupload.save()
            # html = '<html><body>The form was valid. Form was %s. Filename was %s (model). finally, in the post request. Request.FILES[\'filename\'] was %s </body></html>' % (form, filename, request.FILES['filename'])
            return redirect('/handlefile')
        return HttpResponse("<html><body>Form was not valid</body></html>")
    else:
        form = UploadFileForm()  #empty, unbound form
        files = FileUpload.objects.all()
        return render(request, 'index.html', {'form': form})
Esempio n. 3
0
def register_upload(request, name, checksum, size, target_dir):
    upload_dir = getattr(settings, "UPLOAD_DIR", None)
    if upload_dir is not None:
        target_dir = os.path.join(upload_dir, target_dir)
        if not target_dir.startswith(upload_dir):
            raise RuntimeError("Target directory (%s) is outside upload dir: %s" % (target_dir, upload_dir))

    upload = FileUpload()
    upload.owner = request.user
    upload.name = name
    upload.checksum = checksum.lower()
    upload.size = size
    upload.target_dir = target_dir
    upload.save()
    return (upload.id, upload.upload_key)
Esempio n. 4
0
def download(request):
    """Saves image from URL and returns ID for use with AJAX script"""
    if not request.user.is_staff:
        raise Http404
    if request.method == "GET":
        f = FileUpload();
        f.title = request.GET["title"] or "untitled"
        f.description = request.GET["description"]
        url = urllib.unquote(request.GET["photo"])
        file_content = urllib.urlopen(url).read()
        file_name = url.split("/")[-1]
        f.save_upload_file(file_name, file_content)
        f.save()
        return HttpResponse("%s" % (f.id))
    else:
        raise Http404
Esempio n. 5
0
def upload_files(request):
	if request.method == 'POST':
		form = UploadForm(request.POST, request.FILES)
		if form.is_valid():
			print "form is valid"
			form_data = form.cleaned_data
			saved_file = handle_uploads(form_data['uploaded_file'], form_data['filename'])
			newdoc = FileUpload()
			newdoc.uploaded_file_url = saved_file
			newdoc.description = form_data['description']
			newdoc.filename = form_data['filename']
			newdoc.save()
			newdoc.allowed_users = form_data['allowed_users']
			newdoc.save()
			messages.add_message(request, messages.INFO, "File "+newdoc.filename+" Uploaded Sucessfully")
			return HttpResponseRedirect(reverse('uploaded_files'))
	form = UploadForm()
	base_template = 'dashboard.html'
	return render(request,'fileupload/upload_file.html',{'form':form, 'base_template':base_template })