Exemplo n.º 1
0
    def post(self):
        ctx = self.get_context()
        form = ctx['form']

        if form.validate():
            project = Project()
            form.populate_obj(project)
            project.users = User.objects.all() # for now, all users are on the projects

            # Check that repo exists and that the user can access it.
            if project.repo:
                if not project.author.github_access:
                    return redirect(url_for('github_login'))
                if not project.ping_repo():
                    flash('The repo <b>%s</b> doesn\'t seem to exist!' % project.repo)
                    form.repo.errors = ['Can\'t access this repo.']
                    return render_template('project/new.html', form=form)

            # Create a Google Drive Folder for this project on its authors account.
            project.create_folder()

            project.save()
            flash('The <b>%s</b> project was successfully summoned.' % project.name)
            return redirect(url_for('project_api', slug=project.slug, _method='GET'))

        flash('You have forgotten something. Without your guidance, we are lost.')
        return render_template('project/new.html', form=form)