コード例 #1
0
ファイル: views.py プロジェクト: berggren/fordropweb
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'])
コード例 #2
0
ファイル: views.py プロジェクト: berggren/fordropweb
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)
コード例 #3
0
ファイル: views.py プロジェクト: berggren/fordropweb
def collection_unfollow(request, id):
    if request.method == 'POST':
        collection = Collection.objects.get(pk=id)
        collection.followers.remove(request.user)
        collection.save()
        for node in collection.nodes.all():
            xmpp.publish(node=node.node, payload=collection.activity_unfollow())
    return HttpResponseRedirect(request.META['HTTP_REFERER'])
コード例 #4
0
ファイル: views.py プロジェクト: berggren/fordropweb
def collection_tag(request, id):
    collection = Collection.objects.get(pk=id)
    if request.method == 'POST':
        form = CollectionTagForm(request.POST, instance=collection)
        if form.is_valid():
            form.save()
        if collection.tags.all:
            for node in collection.nodes.all():
                xmpp.publish(node=node.node, payload=collection.activity_tags())
    return HttpResponseRedirect(request.META['HTTP_REFERER'])
コード例 #5
0
ファイル: views.py プロジェクト: berggren/fordropweb
def file_tag(request, id):
    file = File.objects.get(pk=id)
    if request.method == 'POST':
        form = FileTagForm(request.POST, instance=file)
        if form.is_valid():
            form.save()
        if file.tags.all:
            for node in file.nodes.all():
                xmpp.publish(node=node.node, payload=file.activity_tags())
    return HttpResponseRedirect(request.META['HTTP_REFERER'])
コード例 #6
0
ファイル: views.py プロジェクト: berggren/fordropweb
def collection_comment(request, id):
    if request.method == 'POST':
        form = CollectionCommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            collection = Collection.objects.get(pk=id)
            comment.user = request.user
            comment.collection = collection
            comment.uuid = uuid.uuid4().urn
            comment.save()
            collection.save()
            for node in collection.nodes.all():
                xmpp.publish(node=node.node, payload=comment.activity())
    return HttpResponseRedirect(request.META['HTTP_REFERER'])
コード例 #7
0
ファイル: views.py プロジェクト: berggren/fordropweb
def collection(request):
    if request.method == 'POST':
        form = CollectionForm(request.POST)
        if form.is_valid():
            collection = form.save(commit=False)
            collection.user = request.user
            collection.uuid = uuid.uuid4().urn
            collection.save()
            collection.followers.add(request.user)
            collection.save()
            form.save_m2m()
            for n in request.POST.getlist('nodes'):
                node = PubSubNode.objects.get(node=int(n))
                collection.nodes.add(node)
                xmpp.publish(node=node.node, payload=collection.activity_fordrop_collection())
                if collection.tags.all():
                    xmpp.publish(node=node.node, payload=collection.activity_tags())
    return HttpResponseRedirect('/collection/%s' % collection.id)