本文整理汇总了Python中models.File.md5方法的典型用法代码示例。如果您正苦于以下问题:Python File.md5方法的具体用法?Python File.md5怎么用?Python File.md5使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.File
的用法示例。
在下文中一共展示了File.md5方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload
# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import md5 [as 别名]
def upload(request, json=False):
if request.method == 'GET':
form = UploadForm()
if request.method == 'POST':
form = UploadForm(request.POST, request.FILES)
if form.is_valid():
data = request.FILES['file']
size = form.cleaned_data['file'].size
expire_date = form.cleaned_data['expire_date'] or one_week_later()
message = form.cleaned_data['message']
receiver = form.cleaned_data['receiver']
if form.cleaned_data['filename_overwrite']:
name = form.cleaned_data['filename_overwrite']
else:
name = form.cleaned_data['file'].name
file = File(name=name, owner=request.user,
expire_date=expire_date, message=message, size=size)
md5 = handle_uploaded_file(name, file.secret, data)
file.md5 = md5
file.save()
if receiver:
downloader = Downloader(email=receiver, file=file)
downloader.save()
url = 'http://%s/files/download/%s/%s' % \
(Site.objects.get_current().domain, file.id, file.secret)
from_ = request.user.email
mailit([receiver], from_, message, url)
if json:
response = {'status': 'ok', 'fileid': file.id}
return HttpResponse(simplejson.dumps(response))
else:
return HttpResponseRedirect('/files/list/')
if json:
response = {'status': 'error', 'message': 'form not valid'}
return HttpResponse(simplejson.dumps(response))
else:
return render_to_response('files/upload.html', {'form': form, }, context_instance=RequestContext(request))