示例#1
0
def instrumentos_borrar():
    resp = checkAccess("ELIMINAR_INSTRUMENTO")
    if not resp == 'true':
        return resp

    # Borrar img
    Instrumento.db = get_db()
    instrumento = Instrumento.find_by_id(request.form['hiddenAluId'])
    if instrumento['imagen'] != "no_image.jpeg" and instrumento['imagen'] != "":
        # pathUrl="flaskps"+url_for('static', filename='uploads/')
        urlImg = path.join(pathUrl, instrumento['imagen'])
        if path.isfile(urlImg):
            remove(urlImg)

    try:
        # Instrumento.db = get_db()
        Instrumento.db.autocommit = False
        Instrumento.delete(request.form['hiddenAluId'])
        Instrumento.db.commit()

        flash("Se eliminó con éxito", "success")
        return redirect(url_for('instrumentos_lista'))

    except Exception as e:
        flash(str(e), "danger")
        Instrumento.db.rollback()
        return redirect(url_for('instrumentos_lista'))
示例#2
0
def index():
    Instrumento.db = get_db()

    User.db = get_db()
    permisos = User.misPermisos(session['id'])
    pag= request.args.get('pagina')

    Configuracion.db = get_db()
    config = Configuracion.all()
    # rango= Instrumento.rangoFind(request.form,config['paginacion'])
    # pag,config['paginacion']
    instrumentos = Instrumento.all(pag, config['paginacion'])
    rango = Instrumento.rango(config['paginacion'])
    return render_template('instrumentos/index.html', instrumentos=instrumentos,pages=config['paginacion'],rango=rango,vista='instrumentos_index', permisos= permisos)
示例#3
0
def instrumentos_create():
    resp = checkAccess("CREAR_INSTRUMENTO")
    if not resp == 'true':
        return resp

    form = FormInstrumento(request.form)

    Nombre = request.form['Nombre']
    Tipo = request.form['Tipo']
    Identificador = request.form['Identificador']

    if not form.validate():
        flash("Error", "danger")
        return instrumentos_nuevo(form)

    # Checkear codigo existente
    Instrumento.db = get_db()
    instrumento = Instrumento.buscar_codigo(Identificador)
    if instrumento != None:
        flash("Error, el IDENTIFICADOR ya existe", "danger")
        return instrumentos_nuevo(form)

    # Guardar imagen
    f = request.files['Imagen']
    if f.filename != "":
        f_extension = f.filename.split('.')[1]
        if not check_img(f_extension):
            return instrumentos_nuevo(form)
        Imagen = "imgID" + request.form['Identificador'] + "." + f_extension
        # pathUrl="flaskps"+url_for('static', filename='uploads/')
        f.save(path.join(pathUrl, Imagen))
    else:
        Imagen = "no_image.jpeg"

    try:
        # Instrumento.db = get_db()
        Instrumento.db.autocommit = False
        Instrumento.create(request.form['Nombre'], request.form['Tipo'],
                           request.form['Identificador'], Imagen)
        Instrumento.db.commit()

        flash("Se creó con éxito", "success")
        return redirect(url_for('instrumentos_lista'))

    except Exception as e:
        flash(str(e), "danger")
        Instrumento.db.rollback()
        # return instrumentos_nuevo(request.form)
        return instrumentos_nuevo(form)
示例#4
0
def find():


    pag= request.args.get('pagina')

    Configuracion.db = get_db()
    config = Configuracion.all()


    Instrumento.db =get_db()

    rango= Instrumento.rangoFind(request.form,config['paginacion'])

    instrumentos = Instrumento.find(request.form,pag,config['paginacion'])
    return render_template('instrumentos/index.html', instrumentos=instrumentos, pages=config['paginacion'],rango=rango)
示例#5
0
def instrumentos_detalle():
    resp = checkAccess("DETALLE_INSTRUMENTO")
    if not resp == 'true':
        return resp

    #Carga los datos de la BD
    Instrumento.db = get_db()
    instrumento = Instrumento.find_by_id(request.form['hiddenid'])

    # Checkear existencia de img
    # pathUrl="flaskps"+url_for('static', filename='uploads/')
    if path.isfile(path.join(pathUrl, instrumento['imagen'])):
        imagen = url_for('static', filename='uploads/' + instrumento['imagen'])
    else:
        imagen = url_for('static', filename='uploads/not_found.jpg')

    #Ver de ruta
    import os
    test = os.getcwd()

    return render_template('pages/instrumentos_detalle.html',
                           titulo="Detalle",
                           instrumento=instrumento,
                           imagen=imagen,
                           test=test)
示例#6
0
def instrumentos_lista(params={"init": 0}, function=1, activo=None, nombre=''):
    resp = checkAccess("LISTADO_INSTRUMENTOS")
    if not resp == 'true':
        return resp

    Pages.db = get_db()
    paginado = Pages.get_paginado()
    params['pag'] = int(paginado['cuerpo'])

    if request.method == 'POST' and 'init' in request.form.keys() and int(
            request.form['init']) >= 0:
        params['init'] = int(request.form['init'])

    filtro = ''

    if ('nombreFiltro' in request.form.keys()):
        if (request.form['nombreFiltro']
                and request.form['nombreFiltro'].strip()):
            nombre = request.form['nombreFiltro']
            function = 0
            filtro = request.form['nombreFiltro']
    #   MODIFICADO PARA USUARIO PERO HAYQ UE AGREGAR LOS FILTROS PARA LA BUSQUEDA

    Instrumento.db = get_db()
    users = Instrumento.get_listado(nombre)

    return render_template('pages/instrumentos_lista.html',
                           users=users,
                           params=params,
                           nombreFiltro=nombre,
                           function=function,
                           filtro=filtro)
示例#7
0
def modificar():
    if not authenticated(session):
        abort(401)

    Instrumento.db = get_db()

    id_instrumento = request.args.get('id')
    data = request.form
    codUnico = Instrumento.find_by_codigo(data['descripcionDeEstado'])

    if codUnico:
        flash("El codigo ya existe.")
        return redirect(url_for('instrumento_update'))
    Instrumento.modificar(data) #agarro los datos del formulario
    

    return redirect(url_for('instrumentos_index'))
示例#8
0
def create():
    Instrumento.db = get_db()
    # raise ValueError(request.form)
    if 'imagen' not in request.files:
        print('No esta la foto')
    #raise ValueError(image64)
    data = request.form

    codUnico = Instrumento.find_by_codigo(data['descripcionDeEstado'])

    if codUnico:
        flash("El codigo ya existe.")
        return redirect(url_for('instrumentos_new'))

    image=request.files['imagen']
    # raise ValueError(image)
    image64=base64.b64encode(image.read())
    Instrumento.create(request.form,image64)
    return redirect(url_for('instrumentos_index'))
示例#9
0
def instrumentos_modificar(form=None):
    resp = checkAccess("MODIFICAR_INSTRUMENTO")
    if not resp == 'true':
        return resp

    Instrumento.db = get_db()
    eliminarImg = {'estado': "", 'valor': ""}
    if form is None:  #Carga los datos de la BD
        instrumento = Instrumento.find_by_id(request.form['idModificar'])
        img = instrumento['imagen']
    else:  #Carga los datos del formulario enviado
        instrumento = {
            'nombre': request.form['Nombre'],
            'tipo_id': int(request.form['Tipo']),
            'codigo': request.form['Identificador'],
            'id': request.form['id']
        }
        instrumentoBD = Instrumento.find_by_id(instrumento['id'])
        img = instrumentoBD['imagen']
        if 'EliminarImg' in request.form:
            eliminarImg['valor'] = "checked"

    # Checkear existencia de img
    # pathUrl="flaskps"+url_for('static', filename='uploads/')
    if path.isfile(path.join(pathUrl, img)):
        imagenActual = url_for('static', filename='uploads/' + img)
    else:
        imagenActual = url_for('static', filename='uploads/not_found.jpg')

    # Eliminar img checkbox
    if img == "no_image.jpeg":
        eliminarImg['estado'] = "disabled"

    TipoInstrumento.db = get_db()
    tipos = TipoInstrumento.all()

    return render_template('pages/instrumentos_nuevo.html',
                           titulo="Modificar",
                           tipos=tipos,
                           form=form,
                           instrumento=instrumento,
                           imagenActual=imagenActual,
                           eliminarImg=eliminarImg)
示例#10
0
def update():
    if not authenticated(session):
        abort(401)
    User.db = get_db()
    permisos = User.misPermisos(session['id'])

    TipoInstrumento.db = get_db()
    tipoInstrumentos = TipoInstrumento.all()


    Instrumento.db = get_db()
    id_instrumento= request.args.get('id')
    instrumento = Instrumento.search(id_instrumento)
    return render_template('instrumentos/update.html', instrumentos=instrumento, tipoInstrumentos=tipoInstrumentos, permisos=permisos)
示例#11
0
def delete():
    Instrumento.db = get_db()
    id_instrumento= request.args.get('id')
    Instrumento.delete(id_instrumento)
    instrumentos = Instrumento.all()
    return render_template('instrumentos/index.html', instrumentos=instrumentos)
示例#12
0
def detail():
    id_instrumento = request.args.get('id')
    Instrumento.db =get_db()
    instrumento = Instrumento.obtenerId(id_instrumento)
    return render_template('instrumentos/show.html',instrumento=instrumento)
示例#13
0
def instrumentos_update():
    resp = checkAccess("MODIFICAR_INSTRUMENTO")
    if not resp == 'true':
        return resp

    form = FormInstrumento(request.form)

    Nombre = request.form['Nombre']
    Tipo = request.form['Tipo']
    Identificador = request.form['Identificador']

    if not form.validate():
        flash("Error", "danger")
        return instrumentos_modificar(form)

    # Checkear codigo existente
    Instrumento.db = get_db()
    instrumento = Instrumento.buscar_codigo(Identificador)
    if instrumento != None:
        cambioDeCodigo = False
        if instrumento['id'] != int(request.form['id']):
            flash("Error, el IDENTIFICADOR ya existe", "danger")
            return instrumentos_modificar(form)
    else:
        cambioDeCodigo = True

    # Guardar imagen
    instrumento = Instrumento.find_by_id(request.form['id'])
    # pathUrl="flaskps"+url_for('static', filename='uploads/')
    original = path.join(pathUrl, instrumento['imagen'])
    f = request.files['Imagen']
    if f.filename != "":
        f_extension = f.filename.split('.')[1]
        if not check_img(f_extension):
            return instrumentos_modificar(form)
        Imagen = "imgID" + request.form['Identificador'] + "." + f_extension
        # Borrar img vieja
        if instrumento['imagen'] != "no_image.jpeg" and instrumento[
                'imagen'] != "" and path.isfile(original):
            remove(original)
        # Guardar nueva
        f.save(path.join(pathUrl, Imagen))
    elif 'EliminarImg' in request.form:
        Imagen = "no_image.jpeg"
        # Borrar img
        if instrumento['imagen'] != "no_image.jpeg" and instrumento[
                'imagen'] != "" and path.isfile(original):
            remove(original)
    else:
        Imagen = ""
        if instrumento['imagen'] != "no_image.jpeg":
            if cambioDeCodigo:
                # Renombrar imagen
                f_extension = instrumento['imagen'].split('.')[1]
                Imagen = "imgID" + request.form[
                    'Identificador'] + "." + f_extension
                if path.isfile(original):
                    rename(original, path.join(pathUrl, Imagen))
            else:
                if instrumento['imagen'] == "":
                    Imagen = "no_image.jpeg"

    try:
        # Instrumento.db = get_db()
        Instrumento.db.autocommit = False
        if Imagen == "":
            Instrumento.updateNoImg(request.form['Nombre'],
                                    request.form['Tipo'],
                                    request.form['Identificador'],
                                    request.form['id'])
        else:
            Instrumento.update(request.form['Nombre'], request.form['Tipo'],
                               request.form['Identificador'], Imagen,
                               request.form['id'])
        Instrumento.db.commit()

        flash("Se modifico con éxito", "success")
        return redirect(url_for('instrumentos_lista'))

    except Exception as e:
        flash(str(e), "danger")
        Instrumento.db.rollback()
        # return instrumentos_modificar(request.form)
        return instrumentos_modificar(form)