本文整理汇总了Python中forms.UploadFileForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python UploadFileForm.save方法的具体用法?Python UploadFileForm.save怎么用?Python UploadFileForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.UploadFileForm
的用法示例。
在下文中一共展示了UploadFileForm.save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: uploader
# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import save [as 别名]
def uploader(request):
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('index'))
else:
form = UploadFileForm()
context = {'form': form}
return render(request, 'uploader.html', context)
示例2: file_upload
# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import save [as 别名]
def file_upload(request):
''' Cuida do upload do arquivo para que o mesmo
seja posteriormente carregado na base de dados '''
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
form.save()
handle_uploaded_file(request.FILES['file'])
return redirect('/success/')
else:
form = UploadFileForm()
return render(request, "file_upload/upload.html", {'form': form})
示例3: file_list
# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import save [as 别名]
def file_list(request):
'''View for files, including upload form'''
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
form.save()
messages.info(request,
'File uploaded as %s' % form.instance.file.name)
return redirect('file_list')
else:
form = UploadFileForm()
return render_to_response(
'ttg/file_list.html',
{'form': form, 'files': MediaFile.objects.all()},
RequestContext(request))
示例4: file_share
# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import save [as 别名]
def file_share(request):
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
result = handle_uploaded_file(request.FILES['file'])
if result:
try:
file = File.objects.get(sha512=result['sha512'], user=request.user)
messages.error(request, 'You have already reported this file')
return HttpResponseRedirect('/file/%s' % file.id)
except ObjectDoesNotExist:
file = form.save(commit=False)
file.uuid = uuid.uuid4().urn
file.user = request.user
file.filename = result['filename']
file.filesize = result['filesize']
file.md5 = result['md5']
file.sha1 = result['sha1']
file.sha256 = result['sha256']
file.sha512 = result['sha512']
file.save()
form.save_m2m()
for n in request.POST.getlist('nodes'):
node = PubSubNode.objects.get(node=int(n))
file.nodes.add(node)
xmpp.publish(node=node.node, payload=file.activity_fordrop_file())
if file.tags.all():
xmpp.publish(node.node, payload=file.activity_tags())
print json.dumps(file.activity_fordrop_file(), indent=4)
messages.success(request, "Sharing is caring, file successfully recieved!")
mail_body = '%s reported the same file as you, %s\n%s' % (file.user.profile.name, file.sha1, file.get_full_uri())
notify_by_mail(users=file.get_reporters(), subject='%s reported the same file as you' % file.user.profile.name, body=mail_body, obj=file)
return HttpResponseRedirect('/file/%s' % file.id)
示例5: upload_file
# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import save [as 别名]
def upload_file(request):
obj = Upload()
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
else:
form = UploadFileForm()
if form.is_valid():
#_upload(request.FILES['file'])
#u.file = _upload(request.FILES['file'])
#u.description = form.cleaned_data['description']
form.save(request, obj)
return HttpResponseRedirect('/up/')
else:
context = {}
context.update(csrf(request))
context.update({'form': form})
return render_to_response('upload/upload.html', context)
示例6: index_page
# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import save [as 别名]
def index_page(request):
cs = Checksum()
uploadform = UploadFileForm()
if request.method == "POST":
hash_type = request.POST.get("hashingtype", "")
string_to_hash = request.POST.get("stringtohash", "")
print hash_type
if not hash_type and not request.POST.get("save_btn"):
uploadform = UploadFileForm()
output = {'uploadform':uploadform, 'if_error':"Select hashing type",}
return render(request,'index.html',output )
if string_to_hash:
#Check that both text and hashing type is given
# Calculate checksum
hash_str = cs.hashStrCalculate(hash_type, string_to_hash)
output = {'uploadform':uploadform, 'info':"Checksum calculated!", 'string_to_hash': string_to_hash, 'hash_type': hash_type, 'hash_':hash_str,}
return render(request,'index.html',output )
#Uploading file
uploadform = UploadFileForm(request.POST,request.FILES)
if uploadform.is_valid():
newfile = uploadform.save(commit=False)
try:
file_ = request.FILES['filename']
path = os.path.join(settings.MEDIA_ROOT, "files_to_check/"+str(file_))
newfile.save()
#calculate checksum
hash_file = cs.hashFileCalculate(hash_type, path)
output = {'info':"Upload successful!", 'uploadform':uploadform, 'uploaded_file':str(file_), 'hash_type': hash_type, 'hash_':hash_file,}
os.remove(path)
except Exception as e:
uploadform = UploadFileForm()
output = {'uploadform':uploadform, 'if_error':"File not selected",}
uploadform = UploadFileForm()
return render(request,'index.html',output )
elif not uploadform.is_valid() and not request.POST.get("save_btn"):
uploadform = UploadFileForm()
output = {'uploadform':uploadform, 'if_error':"File too big!",}
return render(request,'index.html',output )
# Save results
if request.POST.get("save_btn"):
# Get parameters when user hits the "save" button
strToSave = request.POST.get("string_to_save")
fileName = request.POST.get("filename_to_save")
typeToSave = request.POST.get("hashtype_to_save")
hashToSave = request.POST.get("hash_to_save")
try:
if strToSave:
#This is used when user pastes text"""
strdb_obj = StrHashdb(string_to_hash=strToSave, hash_of_string=hashToSave, hash_type=typeToSave)
strdb_obj.save()
elif fileName:
#This is used when user uploads file
filedb_obj = Hashdb(filename=fileName, filehash=hashToSave, hash_type=typeToSave)
filedb_obj.save()
output = {'uploadform':uploadform, 'info':"Data has been saved and is now searchable from database!"}
return render(request,'index.html',output )
except Exception as e:
raise e
uploadform = UploadFileForm()
output = {'uploadform':uploadform}
return render(request, 'index.html', output)