예제 #1
0
def upload (request):
	currentPage = "upload"
	auth = request.user.is_authenticated()
	if (request.method=="POST"):	# If the form has been submitted...
		filename = request.FILES['file'].name
		if (filename.endswith('.pdf')):	# allow users to only upload pdf files
			form = uploadfileform(request.POST, request.FILES) # A form bound to the POST data
			if form.is_valid():	# All validation rules pass
				data = form.cleaned_data
				# generate default report title if not specified by user
				if (data['title'] == ''):
					data['title'] = "Report for " + filename
				unid = unicode(uuid.uuid4())
				filename = unid + ".pdf"
				filepath = MEDIA_ROOT + "public/"
				# if user has logged in, save uploaded file to user's folder
				if auth:
					filepath = request.user.get_profile().filepath
				fileObj = UserFile(uid = unid, owner = request.user.username, title = data['title'], notes = data['notes'])
				fileObj.file.save(filename, ContentFile(request.FILES['file'].read()))
				fileObj.save()
				process_file(filename, filepath) #	call function to run evaluator on uploaded file
				if auth:
					user = request.user.get_profile()
					user.filecount = user.filecount + 1
					user.save()
					return HttpResponseRedirect('/accounts/profile/managereports/')
				else:
					return render_to_response("upload/processing.html", {"uid": fileObj.uid})
		else:
			message = "Not a PDF file"
	form = uploadfileform()
	return render_to_response("upload/fileupload.htm", locals(), context_instance=RequestContext(request))
예제 #2
0
def upload(request):
    """ Upload View """

    t = loader.get_template('upload.html')
    c = Context({
        'files': UserFile.objects.all()
    })
    if request.POST:
        uf = UserFile(user_file=request.FILES['userfile'], absolute_path=request.POST.get('absolute_path', ''),
            content_type=request.FILES['userfile'].content_type)
        uf.save()
        if not uf.id:
            raise Exception('Not saved!')
        return HttpResponse(dumps({'name': uf.user_file.name, 'url': uf.user_file.url}), mimetype='application/json')

    return HttpResponse(t.render(c))
예제 #3
0
def attach(request):
    "Obtains the attachment and saves it to the disk"
    if request.method == 'POST':
        form = AttachmentForm(request.POST, request.FILES)
        if form.is_valid():
            f = request.FILES['attachment']
            record = UserFile(name = f.name,
                attachment = os.path.join(settings.ATTACHMENT_FOLDER, form.cleaned_data['attachment'].name),
                mime_type = f.content_type)
            handle_uploaded_file(f)
            record.save()
            return HttpResponseRedirect('/filemanager/list/')
    else:
        form = AttachmentForm()
    return render_to_response('attach.html', {'form':form},
            context_instance = RequestContext(request))
예제 #4
0
파일: views.py 프로젝트: th4nk/BBS_Pro
def register(request):
    if request.method == 'POST':
        uf = UserForm(request.POST)
        if uf.is_valid():
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            email = uf.cleaned_data['email']

            user = UserFile()
            user.username = username
            user.password = password
            user.email = email
            user.save()

            return render_to_response('success.html',{'username':username})
    else:
        uf = UserForm()

    return render_to_response('register.html',{'uf':uf})