Example #1
0
def projectPage(projectName):
  currentUser = getCurrentUser()
  project = ProjectModel.getProjectByProjectName(projectName)

  if project == None:
    return render_template(
      "not-found.html",
      title = "Project Not Found!",
      msg = "The project you trying to access not found!",
      currentUser = getCurrentUser()
      )

  projectLinks = ProjectModel.getProjectLinks(project["pid"])
  lastProjectPosts = ProjectPostModel.getLastProjectPosts(project["pid"], 10, getCurrentUid())
  numberOfMembers = ProjectModel.getNumberOfMembers(project["pid"])
  numberOfEmptySeaters = SeaterModel.getProjectEmptySeaterNumber(project["pid"])
  popularProjects = ProjectModel.getPopularProjects(10)
  whoToFollowList = UserModel.getWhoToFollowList(5, getCurrentUid())


  return render_template(
    "project-page.html",
    currentUser = currentUser,
    project = project,
    projectLinks = projectLinks,
    lastProjectPosts = lastProjectPosts,
    numberOfMembers = numberOfMembers,
    numberOfEmptySeaters = numberOfEmptySeaters,
    popularProjects = popularProjects,
    whoToFollowList = whoToFollowList
    )
Example #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")