예제 #1
0
파일: project.py 프로젝트: fozbek/devSeater
def createAProject():
  if request.method == "POST":
    projectName = request.form.get("project-name")
    shortDescription = request.form.get("short-description")
    fullDescription = request.form.get("full-description")
    links = request.form.getlist("links[]")
    linkNames = request.form.getlist("link-names[]")

    errorMessages = dict()

    if not isValidProjectName(projectName):
      errorMessages["projectName"] = "A project name can consist of letters, numbers and - _ characters."
    
    if shortDescription == "" or shortDescription == None:
      errorMessages["shortDescription"] = "Short description cannot be empty."
    
    if not errorMessages:
      project = {
        "project_name": projectName,
        "short_description": shortDescription,
        "full_description": fullDescription
      }
      ProjectModel.createProject(project, session["uid"])

      #Add project links
      pid = ProjectModel.getProjectByProjectName(projectName)["pid"]
      
      if pid != None:
        for link, name in zip(links, linkNames):
          ProjectModel.addProjectLink(pid, name, link)

      return redirect(url_for("projectPage", projectName = projectName))
    else:
      return render_template("create-a-project.html", 
      currentUser = getCurrentUser(), 
      errorMessages = errorMessages, 
      form = request.form)

  else:
    return render_template("create-a-project.html", currentUser = getCurrentUser())
예제 #2
0
def projectLinks(pid):
    if request.method == "GET":
        #Getting all project's links
        links = ProjectModel.getProjectLinks(pid)
        return json.dumps(links, cls=DateTimeEncoder)
    elif request.method == "POST":
        #Stripping
        data = json.loads(request.data)
        data["name"] = data["name"].strip()
        data["link"] = data["link"].strip()

        #Adding new project link
        if data["name"] != "" and data["link"] != "":
            plid = ProjectModel.addProjectLink(pid, data["name"], data["link"])
            return json.dumps({"result": "success", "plid": plid})

    elif request.method == "PUT" and isLoggedIn():
        #Updating a user link
        data = json.loads(request.data)
        plid = request.args.get("plid")
        link = ProjectModel.getProjectLink(plid)

        if ProjectModel.isProjectAdmin(getCurrentUid(), pid):
            ProjectModel.updateProjectLink(plid, data["name"], data["link"])
            return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")

    else:
        #Delete a user link
        #DELETE request

        plid = request.args.get("plid")
        link = ProjectModel.getProjectLink(plid)

        if isLoggedIn() and ProjectModel.isProjectAdmin(
                getCurrentUid(), link["pid"]):
            ProjectModel.removeProjectLink(plid)
            return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")
    return render_template("private-api/unknown-request.html")