Beispiel #1
0
def project_file_rename(request):
    """
    rename file name
    :param request: request object
    :return: result of rename
    """
    if request.method == 'POST':
        data = json.loads(request.body)
        pre = join(data['path'], data['pre'])
        new = join(data['path'], data['new'])
        if not is_in_curdir(pre) or not is_in_curdir(new):
            return JsonResponse({'result': '0'})
        os.rename(pre, new)
        return JsonResponse({'result': '1'})
Beispiel #2
0
def project_file_delete(request):
    """
    delete project file
    :param request: request object
    :return: result of delete
    """
    if request.method == 'POST':
        data = json.loads(request.body)
        path = join(data['path'], data['label'])
        if not is_in_curdir(path):
            return JsonResponse({'result': '0'})
        result = os.remove(path)
        return JsonResponse({'result': result})
Beispiel #3
0
def project_file_create(request):
    """
    create project file
    :param request: request object
    :return: result of create
    """
    if request.method == 'POST':
        data = json.loads(request.body)
        path = join(data['path'], data['name'])
        if not is_in_curdir(path):
            return JsonResponse({'result': '0'})
        open(path, 'w', encoding='utf-8').close()
        return JsonResponse({'result': '1'})
Beispiel #4
0
def project_file_read(request):
    """
    get content of project file
    :param request: request object
    :return: file content
    """
    if request.method == 'POST':
        data = json.loads(request.body)
        path = join(data['path'], data['label'])
        if not is_in_curdir(path):
            return JsonResponse({'result': '0'})
        # binary file
        with open(path, 'rb') as f:
            return HttpResponse(f.read().decode('utf-8'))
Beispiel #5
0
def project_file_update(request):
    """
    update project file
    :param request: request object
    :return: result of update
    """
    if request.method == 'POST':
        data = json.loads(request.body)
        path = join(data['path'], data['label'])
        code = data['code']
        if not is_in_curdir(path):
            return JsonResponse({'result': '0'})
        with open(path, 'w', encoding='utf-8') as f:
            f.write(code)
            return JsonResponse({'result': '1'})