Пример #1
0
def projectPhoto(pid):
    project = ProjectModel.getProject(pid)
    if not ProjectModel.isProjectAdmin(getCurrentUid(), pid):
        return render_template("private-api/forbidden-request.html")

    if request.method == "POST":
        size = len(request.data) / 1000000
        if size > 2:
            return json.dumps({
                "result": "fail",
                "msg": "File can not be more than 2 MB"
            })

        newFileName = str(pid) + "_" + generateCode(10) + ".jpg"

        with open(UPLOAD_FOLDER + "/projects/pp/" + newFileName, "wb") as fh:
            fh.write(request.data)
            ProjectModel.updateProjectPhoto(pid, newFileName)

            #Delete old uploaded file
            if project["photo"] != None:
                try:
                    os.remove(UPLOAD_FOLDER + "/projects/pp/" +
                              project["photo"])
                except:
                    print("File couldn't be uploaded.")

            return json.dumps({"result": "success"})
    return json.dumps({"result": "fail"})
Пример #2
0
def getProject(pid):
    project = ProjectModel.getProject(pid)

    return json.dumps(project, cls=DateTimeEncoder)