Beispiel #1
0
def novo():
    nucleos = [(c.id, c.descricao) for c in Nucleo.query.order_by(Nucleo.descricao).all()]
    
    form = EventoForm()
    form.id_nucleo.choices = nucleos
    form.id_nucleo.choices.insert(0, (0, 'Selecione...'))

    if request.method == "POST" and form.validate_on_submit():
        evento = Evento()
        form.populate_obj(evento)

        if evento.id_nucleo == 0:
            evento.id_nucleo = None

        db.session.add(evento)
        db.session.commit()
        
        flash("Evento adicionado com sucesso!", "success")
        return redirect("/evento/")

        
    return render_template("evento/form.html", form = form, menu='eventos')
Beispiel #2
0
def editar(id):
    evento = Evento.query.get_or_404(id)   
    nucleos = [(c.id, c.descricao) for c in Nucleo.query.order_by(Nucleo.descricao).all()]

    if is_accessible() or (g.user.id_nucleo == evento.id_nucleo):
        form = EventoForm(obj=evento)

        form.id_nucleo.choices = nucleos
        form.id_nucleo.choices.insert(0, (0, "Selecione...")) 
        
        if request.method == "POST" and form.validate_on_submit():
            form.populate_obj(evento)
            
            if evento.id_nucleo == 0:
                evento.id_nucleo = None
            
            db.session.commit()

            flash(u"Evento editado com sucesso!", "success")
            return redirect("/evento/")
    else:
        abort(403)

    return render_template("evento/form.html", form = form, menu='eventos')