Example #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"})
Example #2
0
def updateProjectFullDescription(pid):
    if not ProjectModel.isProjectAdmin(getCurrentUid(), pid):
        return render_template("private-api/forbidden-request.html")

    description = json.loads(request.data)["description"]

    ProjectModel.updateFullDescription(pid, description)
    return json.dumps({"result": "success"})
Example #3
0
def updateProjectName(pid, newName):
    if not ProjectModel.isProjectAdmin(getCurrentUid(), pid):
        return render_template("private-api/forbidden-request.html")

    if not isValidProjectName(newName):
        return json.dumps({
            "result": "fail",
            "msg": "Project name is not valid"
        })

    ProjectModel.updateProjectName(pid, newName)
    return json.dumps({"result": "success"})
Example #4
0
def seaterPage(projectName, sid):
  project = ProjectModel.getProjectByProjectName(projectName)
  seater = SeaterModel.getSeater(sid, getCurrentUid())
  seater["skills"] = SkillModel.getSeaterSkills(sid)
  assignedUser = UserModel.getUser(seater["uid"])
  seater["isProjectAdmin"] = ProjectModel.isProjectAdmin(getCurrentUid(), project["pid"])

  return render_template(
    "seater-page.html",
    currentUser= getCurrentUser(),
    seater = seater,
    assignedUser = assignedUser
  )
Example #5
0
def aspireSeater(sid):
    seater = SeaterModel.getSeater(sid)
    if ProjectModel.isProjectAdmin(getCurrentUid(), seater["pid"]):
        SeaterModel.assignUser(getCurrentUid(), sid)
    else:
        SeaterModel.aspireSeater(getCurrentUid(), sid)
    return json.dumps({"result": "success"})
Example #6
0
def sitemap():
    lastUsers = UserModel.getLastUsers(500)
    lastProjects = ProjectModel.getLastProjects(500)

    return render_template("sitemap.xml",
                           lastUsers=lastUsers,
                           lastProjects=lastProjects,
                           SITE_ADDR=SITE_ADDR)
Example #7
0
def getPopularProjects():
    howMany = request.args.get("how-many")

    if howMany == None:
        howMany = 4

    projects = ProjectModel.getPopularProjects(howMany)

    return json.dumps(projects, cls=DateTimeEncoder)
Example #8
0
def removeSeater(sid):
    seater = SeaterModel.getSeater(sid)
    if seater != None:
        if ProjectModel.isProjectAdmin(getCurrentUid(), seater["pid"]):
            SeaterModel.removeSeater(sid)
            return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")
    return render_template("private-api/unknown-request.html")
Example #9
0
def generalSearch(query):
    userResults = UserModel.searchUsers(query, 5)
    projectResults = ProjectModel.searchProjects(query, 5)

    return json.dumps(
        {
            "userResults": userResults,
            "projectResults": projectResults
        },
        cls=DateTimeEncoder)
Example #10
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")
Example #11
0
def assignUser(sid, uid):
    seater = SeaterModel.getSeater(sid)

    if seater != None:
        if ProjectModel.isProjectAdmin(getCurrentUid(), seater["pid"]):
            if SeaterModel.isThereSeaterAspiration(uid, sid):
                SeaterModel.assignUser(uid, sid)
                return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")

    return render_template("private-api/unknown-request.html")
Example #12
0
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())
Example #13
0
def dismissUserFromSeater(sid):
    seater = SeaterModel.getSeater(sid)

    if seater != None:
        if ProjectModel.isProjectAdmin(getCurrentUid(),
                                       seater["pid"]) or (seater["uid"]
                                                          == getCurrentUid()):
            SeaterModel.dismissUser(sid)
            SeaterModel.cancelAspirationToTheSeater(seater["uid"], sid)
            return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")

    return render_template("private-api/unknown-request.html")
Example #14
0
def saveSeater(pid):
    if ProjectModel.isProjectAdmin(getCurrentUid(), pid):
        seater = json.loads(request.data)
        seater["pid"] = pid

        if request.method == "POST":
            # Create seater

            sid = SeaterModel.createSeater(pid, seater)

            #Add skills
            for skill in seater["skills"]:
                SkillModel.addSeaterSkill(sid, skill)

            return json.dumps({"result": "success", "sid": sid})
        else:
            # Update seater

            SeaterModel.updateSeater(seater["sid"], seater)

            # Get current skills
            currentSkills = [
                i["name"] for i in SkillModel.getSeaterSkills(seater["sid"])
            ]

            skillsToDelete = set(currentSkills).difference(
                set(seater["skills"]))
            skillToAdd = set(seater["skills"]).difference(set(currentSkills))

            # Delete skills
            for skill in skillsToDelete:
                skill.strip()
                if skill != None and skill != "":
                    SkillModel.removeSeaterSkill(seater["sid"], skill)

            # Add skills
            for skill in skillToAdd:
                skill.strip()
                if skill != None and skill != "":
                    SkillModel.addSeaterSkill(seater["sid"], skill)

            return json.dumps({"result": "success"})

    return render_template("private-api/forbidden-request.html")
Example #15
0
def seaterSkills():
    if request.method == "GET":
        #Get seater skills
        sid = request.args.get("sid")

        if sid != None:
            skills = SkillModel.getUserSkills(getCurrentUid)
            return json.dumps(skills, cls=DateTimeEncoder)
        return render_template("private-api/unknown-request.html")

    elif request.method == "POST" and isLoggedIn():
        #Add seater skill
        sid = request.args.get("sid")
        skill = request.args.get("skill")

        pid = SeaterModel.getSeater(sid)["pid"]

        if ProjectModel.isProjectAdmin(getCurrentUid(), pid):
            if skill != None:
                SkillModel.addSeaterSkill(sid, skill)
                return json.dumps({"result": "success"})

    else:
        #Delete a user skill
        skid = request.args.get("skid")

        if skid != None and isLoggedIn():
            skill = SkillModel.getUserSkill(skid)

            if skill["uid"] == getCurrentUid():
                SkillModel.removeUserSkill(skid)
                return json.dumps({"result": "success"})
            else:
                return render_template("private-api/forbidden-request.html")

    return render_template("private-api/unknown-request.html")
Example #16
0
def projectPosts(pid):
    if request.method == "GET":
        #Get last posts
        ppid = request.args.get("ppid")
        if ppid == None:
            posts = ProjectPostModel.getLastProjectPosts(
                pid, 10, getCurrentUid())
        else:
            posts = ProjectPostModel.getPreviousProjectPosts(
                pid, ppid, 10, getCurrentUid())

        return json.dumps(posts, cls=DateTimeEncoder)

    elif request.method == "POST" and isLoggedIn():
        if not ProjectModel.isProjectMember(getCurrentUid(), pid):
            return render_template("private-api/forbidden-request.html")

        #Stripping
        data = json.loads(request.data)
        data["post"] = data["post"].strip()

        if data["post"] != "":
            #Add project post
            ProjectPostModel.addProjectPost(getCurrentUid(), pid, data["post"])
            return json.dumps({"result": "success"})
        else:
            return json.dumps({
                "result": "fail",
                "msg": "post cannot be empty"
            })

    elif request.method == "PUT" and isLoggedIn():
        if not ProjectModel.isProjectMember(getCurrentUid(), pid):
            return render_template("private-api/forbidden-request.html")

        #Stripping
        data = json.loads(request.data)
        data["post"] = data["post"].strip()

        #Update project post
        ppid = request.args.get("ppid")

        #Validate
        if data["post"] == "" or ppid == None:
            return json.dumps({
                "result": "fail",
                "msg": "ppid and post cannot be empty"
            })

        post = ProjectPostModel.getProjectPost(ppid)

        if post["uid"] == getCurrentUid():
            ProjectPostModel.updateProjectPost(ppid, data["post"])
            return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")

    else:
        #Delete a project post
        ppid = request.args.get("ppid")
        post = ProjectPostModel.getProjectPost(ppid, getCurrentUid())

        if post["uid"] == getCurrentUid() and isLoggedIn():
            ProjectPostModel.removeProjectPost(ppid)
            return json.dumps({"result": "success"})
        else:
            return render_template("private-api/forbidden-request.html")
    return render_template("private-api/unknown-request.html")
Example #17
0
def getProjectAdmins(pid):
    admins = ProjectModel.getProjectAdmins(pid)
    return json.dumps(admins, cls=DateTimeEncoder)
Example #18
0
def getProject(pid):
    project = ProjectModel.getProject(pid)

    return json.dumps(project, cls=DateTimeEncoder)
Example #19
0
def getUserProjects(uid):
    projects = ProjectModel.getUserProjects(uid)

    return json.dumps(projects, cls=DateTimeEncoder)
Example #20
0
def seaterAspirationNumber(sid):
    seater = SeaterModel.getSeater(sid)
    if ProjectModel.isProjectAdmin(getCurrentUid(), seater["pid"]):
        number = SeaterModel.getSeaterAspirationNumber(sid)
        return json.dumps({"number": number})
    return render_template("private-api/forbidden-request.html")
Example #21
0
def seaterAspirations(sid):
    seater = SeaterModel.getSeater(sid)
    if ProjectModel.isProjectAdmin(getCurrentUid(), seater["pid"]):
        aspirations = SeaterModel.getSeaterAspirations(sid)
        return json.dumps(aspirations, cls=DateTimeEncoder)
    return render_template("private-api/forbidden-request.html")
Example #22
0
def index():
    if not isLoggedIn():
        if request.method == "POST":
            # USER REGISTRATION

            email = request.form.get("email").strip()
            name = request.form.get("name").strip()
            username = request.form.get("username").strip()
            password = request.form.get("password").strip()
            terms = request.form.get("terms")

            #Validate all values
            errorMessages = dict()
            if (not isValidEmail(email)):
                errorMessages["email"] = "Please enter a valid email address"
            elif (UserModel.isThereThisEmail(email)):
                errorMessages["email"] = "This email address is already taken"

            if (len(name) < 3):
                errorMessages["name"] = "Name should be at least 3 characters"

            if (not isValidUsername(username)):
                errorMessages[
                    "username"] = "******"
            elif (UserModel.isThereThisUsername(username)):
                errorMessages["username"] = "******"

            if not isValidPassword(password):
                errorMessages[
                    "password"] = "******"

            if (terms != "on"):
                errorMessages["terms"] = "You should accept terms"

            if (not errorMessages):
                UserModel.addUser({
                    "email": email,
                    "username": username,
                    "full_name": name,
                    "password": password
                })

                sendVerificationEmail(email)

                flash(
                    "User created successfully, please check your inbox for email verification",
                    "success")

                return redirect(url_for("login"))

            else:
                return render_template("intro/intro.html",
                                       form=request.form,
                                       errorMessages=errorMessages)

        else:
            return render_template("intro/intro.html")
    else:
        #Logged In

        #Get User Projects
        userProjects = ProjectModel.getUserProjects(session["uid"])
        lastFollowingPosts = UserPostModel.getLastFollowingPosts(
            session["uid"], 10)

        popularProjects = ProjectModel.getPopularProjects(10)
        whoToFollowList = UserModel.getWhoToFollowList(5, getCurrentUid())

        #Get Current User Informations
        currentUser = UserModel.getUser(session["uid"])

        return render_template("index.html",
                               userProjects=userProjects,
                               popularProjects=popularProjects,
                               lastFollowingPosts=lastFollowingPosts,
                               currentUser=currentUser,
                               whoToFollowList=whoToFollowList)
Example #23
0
def getProjectMembers(pid):
    members = ProjectModel.getMembers(pid, getCurrentUid())

    return json.dumps(members, cls=DateTimeEncoder)
Example #24
0
def isThereThisProjectName(name):
    result = ProjectModel.isThereThisProjectName(name)

    return json.dumps({"result": result})
Example #25
0
def getNumberOfMembers(pid):
    number = ProjectModel.getNumberOfMembers(pid)

    return json.dumps({"number": number})
Example #26
0
def isProjectAdmin(pid, uid):
    result = ProjectModel.isProjectAdmin(uid, pid)
    return json.dumps({"result": result})