本文整理汇总了Python中forms.UploadFileForm.save_m2m方法的典型用法代码示例。如果您正苦于以下问题:Python UploadFileForm.save_m2m方法的具体用法?Python UploadFileForm.save_m2m怎么用?Python UploadFileForm.save_m2m使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.UploadFileForm
的用法示例。
在下文中一共展示了UploadFileForm.save_m2m方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: file_share
# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import save_m2m [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)