def file_clone(request, id): ref_file = File.objects.get(pk=id) if request.user in ref_file.get_reporters(): messages.error(request, 'You have already reported this file') return HttpResponseRedirect(request.META['HTTP_REFERER']) file = File.objects.create( uuid = uuid.uuid4().urn, user = request.user, filename = ref_file.filename, filesize = ref_file.filesize, md5 = ref_file.md5, sha1 = ref_file.sha1, sha256 = ref_file.sha256, sha512 = ref_file.sha512 ) for tag in ref_file.tags.all(): file.tags.add(tag) for node in ref_file.nodes.all(): file.nodes.add(node) xmpp.publish(node=node.node, payload=file.activity_tags()) if file.tags.all(): xmpp.publish(node.node, payload=file.activity_tags()) file.save() 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(request.META['HTTP_REFERER'])
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)