Esempio n. 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"})
Esempio n. 2
0
    def post(self, username):
        form = RepositoryForm(request.form)

        if form.validate():
            response = self.rest.postForm(
                  form.toDict(),
                  '/%s' % username,
                  username = session['user.username'],
                  password = session['user.password']
              )

            data = json.loads(response)

            flash("Repository created!", "success")

            return redirect(url_for('repos',
                        username=username,
                        reponame=form.name.data
                      )
                    )

        action = url_for('repos', username=username)
        return render_template('repository/form.html', form=form,
                                    username=username, action=action,
                                    header='Create Repository')
Esempio n. 3
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})
Esempio n. 4
0
    def put(self, username, reponame):
        form = RepositoryForm(request.form)

        if form.validate():
            response = self.rest.putForm(
                  form.toDict(),
                  '/%s/%s' % (username, reponame),
                    username = session['user.username'],
                    password = session['user.password']
              )

            repo = json.loads(response)['repo']

            flash('Repository successfully edited', 'success')

            return redirect(url_for('repos',
                                      username = repo['owner']['username'],
                                      reponame = repo['name']))


        action = url_for('repos', username=username, reponame = reponame) +\
                            '?__METHOD_OVERRIDE__=PUT'
        return render_template('repository/form.html', form=form,
                                    username=username, action=action,
                                    header='Edit Repository')