예제 #1
0
def post():
    form = ColabForm()
    if form.validate_on_submit():
        objeto = ColabModel(form.colab_id.data, form.nome.data,
                            form.idade.data, form.cargo.data)
        colab = ColabModel.find_colab(objeto.colab_id)
        if colab:
            return render_template("post.html",
                                   form=form,
                                   colab_encontrado=colab,
                                   colab_novo=None)
        else:
            objeto.save_colab()
            return render_template("post.html",
                                   form=form,
                                   colab_novo=objeto,
                                   colab_encontrado=None)
    return render_template("post.html", form=form)
예제 #2
0
 def delete(self, colab_id):
     colab = ColabModel.find_colab(colab_id)
     if colab:
         try:
             colab.delete_colab()
         except:
             return {
                 'message': 'An error ocurred trying to delete colab'
             }, 500
         return {'message': 'Colab deleted.'}, 200
     return {'message': 'Colab not found.'}, 404
예제 #3
0
def delete():
    form = Colab_Form()
    if form.validate_on_submit():
        colab = ColabModel.find_colab(form.colab_id.data)
        Colab.delete(Colab, form.colab_id.data)
        if colab:
            return render_template("delete.html", form=form, colab=colab)
        else:
            return render_template("delete.html",
                                   form=form,
                                   colab=colab,
                                   aux=True)
    return render_template("delete.html", form=form)
예제 #4
0
def get():
    form = Colab_Form()
    if form.validate_on_submit():
        colab = ColabModel.find_colab(form.colab_id.data)
        if colab:
            return render_template("get.html",
                                   form=form,
                                   colab=colab,
                                   aux=None)
        else:
            return render_template("get.html",
                                   form=form,
                                   colab=colab,
                                   aux=True)
    return render_template("get.html", form=form)
예제 #5
0
    def post(self, colab_id):
        if ColabModel.find_colab(colab_id):
            return {
                'message': 'Colab id "{}" already exists.'.format(colab_id)
            }, 400

        dados = Colab.argumentos.parse_args()
        colab = ColabModel(colab_id, **dados)
        try:
            colab.save_colab()
        except:
            return {
                'message': 'An internal error ocurred trying to save colab.'
            }, 500
        return colab.json()
예제 #6
0
    def put(self, colab_id):

        dados = Colab.argumentos.parse_args()
        colab_encontrado = ColabModel.find_colab(colab_id)
        if colab_encontrado:
            colab_encontrado.update_colab(**dados)
            colab_encontrado.save_colab()
            return colab_encontrado.json(), 200
        colab = ColabModel(colab_id, **dados)
        try:
            colab.save_colab()
        except:
            return {
                'message': 'An internal error ocurred trying to save colab.'
            }, 500
        return colab.json(), 201
예제 #7
0
 def get(self, colab_id):
     colab = ColabModel.find_colab(colab_id)
     if colab:
         return colab.json()
     return {'message': 'Colab not found'}, 404