예제 #1
0
def create():
    if not authenticated(session):
        return render_template('auth/login.html')
    ok = True
    if not pageState():
        ok = False
        for permiso in session['permisos']:
            if "VER_EN_MANTENIMIENTO" == permiso['nombre']:
                ok = True
    if not ok:
        return render_template('error/mantenimiento.html')
    if not usuarioTienePermiso("CREAR_TALLER"):
        return redirect(url_for('pages_home'))

    Taller.db = get_db()

    res = Taller.create(request.form['nombre'], request.form['nombrecorto'],
                        request.form['nucleo'])
    Taller.assign_ciclo(res['idInsertado'], request.form['ciclo'])
    if request.form['docente'] != "0":
        Taller.assign_docente(request.form['docente'], res['idInsertado'])

    Taller.db.commit()

    flash("El taller ha sido creado correctamente.", "success")
    if ('clid' in request.form.keys()):
        return ciclos.detalle()
    return redirect(url_for('listado_talleres'))
예제 #2
0
def new():
    s_config = siteconfig.get_config()
    if not has_permission("taller_new", session) or (
        s_config["modo_mantenimiento"] == 1 and not has_role("administrador", session)
    ):
        abort(401)

    form = TallerForm()

    op_response = dict()

    if form.validate_on_submit():
        params = request.form.to_dict()

        created = Taller.create(params)

        if created:
            op_response["msg"] = "Se ha agregado al taller con éxito"
            op_response["type"] = "success"
        else:
            op_response["msg"] = "Ha ocurrido un error al crear el Taller"
            op_response["type"] = "error"
            abort(make_response(jsonify(op_response), 422))

    else:
        if len(form.errors) >= 2:
            op_response["msg"] = "Complete todos los datos del nuevo Taller"
            op_response["type"] = "error"
        else:
            error_msg = "".join(list(form.errors.values())[0]).strip("'[]")
            op_response["msg"] = error_msg
            op_response["type"] = "error"

        abort(make_response(jsonify(op_response), 400))

    return make_response(jsonify(op_response), 201)