Example #1
0
    def put(self, username, reponame):
        form = RepositoryForm(request.form, csrf_enabled=False)

        if not "private" in request.form or request.form["private"] == "False":
            form.private.data = False

        if form.validate():
            user = User.query.filter_by(username=username).first()
            repo = Repository.query.filter_by(name=reponame, owner=user).first()
            repo.name = self._sanitize(form.name.data)
            repo.description = form.description.data
            repo.private = bool(form.private.data)
            repo.contributers = [user] + [
                User.query.filter_by(username=c.strip()).first() for c in form.contributers.data.split(",")
            ]

            print "Contributers:" + str(repo.contributers)

            db.session.add(repo)
            db.session.commit()

            if repo.name != reponame:
                shutil.move(Repository._path(user.username, reponame), Repository._path(user.username, repo.name))

            return jsonify(repo=repo.toDict())

        return jsonifiy({"status": "invalid data"})
Example #2
0
    def post(self, username):
        form = RepositoryForm(request.form, csrf_enabled=False)
        reponame = self._sanitize(form.name.data)

        if not "private" in request.form or request.form["private"] == "False":
            form.private.data = False

        if form.validate():
            user = User.query.filter_by(username=session["identity.name"]).first()

            if user.username == username:
                repo = Repository(reponame, user)
                repo.owner = user
                repo.description = form.description.data
                repo.private = bool(form.private.data)
                repo.contributers = [user] + [
                    User.query.filter_by(username=c.strip()).first() for c in form.contributers.data.split(",")
                ]

                db.session.add(repo)
                db.session.commit()

                return jsonify(repo=repo.toDict())

        return jsonify({"error": form.errors})
Example #3
0
    def delete(self, username, reponame):
        user = User.query.filter_by(username=username).first()
        repo = Repository.query.filter_by(name=reponame, owner=user).first()

        if repo != None and repo.owner.username == session["identity.name"]:

            shutil.rmtree(Repository._path(repo.owner.username, reponame))
            db.session.delete(repo)
            db.session.commit()

            return jsonify({"status": "success"})

        return jsonifiy({"status": "invalid data"})