Beispiel #1
0
def upload_revision(request):
    response = {}
    status = 405
    can_save = False
    document_id = request.POST['document_id']
    document = Document.objects.filter(id=int(document_id)).first()
    if document:
        if document.owner == request.user:
            can_save = True
        else:
            access_rights = AccessRight.objects.filter(
                document=document, user=request.user)
            if len(access_rights) > 0 and access_rights[
                0
            ].rights == 'write':
                can_save = True
    if can_save:
        status = 201
        revision = DocumentRevision()
        revision.file_object = request.FILES['file']
        revision.file_name = request.FILES['file'].name
        revision.note = request.POST['note']
        revision.document_id = document_id
        revision.save()
    return JsonResponse(
        response,
        status=status
    )
Beispiel #2
0
def upload_js(request):
    response = {}
    can_save = False
    status = 405
    if request.is_ajax() and request.method == 'POST':
        document_id = request.POST['document_id']
        document = Document.objects.filter(id=int(document_id))
        if len(document) > 0:
            document = document[0]
            if document.owner == request.user:
                can_save = True
            else:
                access_rights = AccessRight.objects.filter(document=document, user=request.user)
                if len(access_rights) > 0 and access_rights[0].rights == 'w':
                    can_save = True
        if can_save:
            status = 201
            revision = DocumentRevision()
            revision.file_object = request.FILES['file']
            revision.file_name = request.FILES['file'].name
            revision.note = request.POST['note']
            revision.document_id = document_id
            revision.save()
    return HttpResponse(
        json.dumps(response),
        content_type = 'application/json; charset=utf8',
        status=status
    )
Beispiel #3
0
def upload_js(request):
    response = {}
    can_save = False
    status = 405
    if request.is_ajax() and request.method == 'POST':
        document_id = request.POST['document_id']
        document = Document.objects.filter(id=int(document_id))
        if len(document) > 0:
            document = document[0]
            if document.owner == request.user:
                can_save = True
            else:
                access_rights = AccessRight.objects.filter(document=document, user=request.user)
                if len(access_rights) > 0 and access_rights[0].rights == 'w':
                    can_save = True
        if can_save:
            status = 201
            revision = DocumentRevision()
            revision.file_object = request.FILES['file']
            revision.file_name = request.FILES['file'].name
            revision.note = request.POST['note']
            revision.document_id = document_id
            revision.save()
    return JsonResponse(
        response,
        status=status
    )