Beispiel #1
0
def mkdir(request, folder, path):
    pathname = request.POST.get("pathname")
    if not pathname:
        return HttpResponseBadRequest("Missing pathname")

    data = FileOperations.mkdir(request.user.username, folder, path, pathname)
    if data.get("success"):
        data["redirect"] = reverse("browse", args=[folder, path+"/"+pathname])
    return JSONResponse(data, {}, response_mimetype(request))
Beispiel #2
0
def browse(request, folder, path, template_name):
    if not FileOperations.valid_file(request.user.username, folder, path):
        raise Http404
    path = path.replace("//", "/")
    path_parts = []
    path_parts_temp = path.split("/")
    path_construct = ""
    for item in path_parts_temp[:-1]:
        path_construct = "%s/%s" % (path_construct, item)
        path_parts.append((path_construct, item))

    ret_dict = {"folder": folder, "path": path, "path_parts": path_parts, "current_path": path_parts_temp[-1] }
    return render_to_response(template_name, ret_dict, context_instance=RequestContext(request))
Beispiel #3
0
def upload(request, folder, path):
    ret_list = []
    data = []
 
    def get_return_dict(file):
        return {"name": file.get("filename"), "size": file.get("size"), 'url': url, "mtime": file.get("mtime", 0), "mtime_readable": file.get("mtime_readable", "-"), 'delete_url': reverse("delete", args=[folder, path+"/"+file.get("filename")]), "delete_type": "POST"}

    if request.FILES:
        files = request.FILES.get("files[]")
    else:
        files = FileOperations.get_files(request.user.username, folder, path)
        for file in files:
             if os.path.isdir(file.get("full_path")):
                 url = reverse("browse", args=[folder, path+"/"+ file.get("filename")])
             else:
                 if folder == "public_html":
                     url = "http://public.futurice.com/~%s/%s/%s" % (request.user.username, path, file.get("filename"))
                 else:
                     url = "/~%s/%s/%s" % (request.user.username, path, file.get("filename"))
             data.append(get_return_dict(file))
        return JSONResponse(data, {}, response_mimetype(request))
    f = files
    FileOperations.upload_file(f, request.user.username, folder, path)

    file = FileOperations.get_file(request.user.username, folder, path, f.name)
    if os.path.isdir(file.get("full_path")):
        url = reverse("browse", args=[folder, path+"/"+ file.get("filename")])
    else:
        if folder == "public_html":
            url = "http://public.futurice.com/~%s/%s/%s" % (request.user.username, path, file.get("filename"))
        else:
            url = "/~%s/%s/%s" % (request.user.username, path, file.get("filename"))
    data.append(get_return_dict(file))
    response = JSONResponse(data, {}, response_mimetype(request))
    response['Content-Disposition'] = 'inline; filename=files.json'
    return response
Beispiel #4
0
def permissions_save(request, folder, path):
    settings = {}
    method = request.POST.get("permission_scheme")
    if not method:
        return HttpResponseBadRequest("Missing method "+json.dumps(request.POST))
    if method == "Public":
        settings["mode"] = "public"
    if method == "Futurice SSO":
        settings["mode"] = "sso"
    if method == "Static account":
        settings["mode"] = "basicauth"
        if not request.POST.get("password") or not request.POST.get("username"):
            return HttpResponseBadRequest("Missing username or password")
        settings["username"] = request.POST.get("username")
        settings["password"] = request.POST.get("password")
    data = FileOperations.save_permissions(request.user.username, folder, path, settings)

    return JSONResponse(data, {}, response_mimetype(request))
Beispiel #5
0
def main(request, template_name):
    ret_dict = {"homefolder_exists": True}
    if not FileOperations.valid_file(request.user.username, "public_html", ""):
        ret_dict["homefolder_exists"] = False
    return render_to_response(template_name, ret_dict, context_instance=RequestContext(request))
Beispiel #6
0
def delete(request, folder, path):
    return JSONResponse(FileOperations.delete_file(request.user.username, folder, path), {}, response_mimetype(request))