Beispiel #1
0
def rsponsable_actualizar():
    try:
        form = json.loads(request.data)
    except json.JSONDecodeError:
        return json.dumps({
            'success': False,
            'error': 'Formato de JSON incorrecto.'
        }), 500

    try:
        responsable = Responsable.get_by_id(db.session, form['id'])
    except KeyError:
        responsable = None

    if responsable is None:
        return json.dumps({
            'success': False,
            'error': 'Responsable no encontrado.'
        }), 500

    try:
        responsable.nombre = form['nombre']
    except:
        json.dumps({'success': False, 'error': 'Error de nombre.'}), 500
    try:
        responsable.telefono = form['telefono']
    except:
        pass
    try:
        responsable.tipo = form['tipo']
    except:
        pass

    try:
        responsable.remove_recurso()
        for r_id in form['recursos']:
            rec = Recurso.get_by_id(db.session, r_id)
            if rec is not None:
                responsable.add_recurso(rec)
    except:
        pass

    try:
        db.session.commit()
    except:
        db.session.rollback()
        return jsonify({'success': False, 'error': 'Error guardando.'}), 500

    return json.dumps({
        'success': True,
        'message': 'Responsable actualizado.'
    }), 200
Beispiel #2
0
def recurso_eliminar(recurso_id):
    try:
        recurso = Recurso.get_by_id(db.session, recurso_id)
        if recurso is None:
            return json.dumps (
                {'success': False, 'error': 'Recurso no encontrado.'} ), 500 , \
                {'ContentType': 'application/json'}

        db.session.delete(recurso)
        db.session.commit()
    except:
        db.session.rollback()
        return json.dumps (
            {'success': False, 'error': 'Error eliminando recurso.'} ), 500 , \
            {'ContentType': 'application/json'}
    return json.dumps (
        {'success': True} ), 200 , \
        {'ContentType': 'application/json'}
Beispiel #3
0
def responsable_crear():
    try:
        form = json.loads(request.data)
    except json.JSONDecodeError:
        return json.dumps({
            'success': False,
            'error': 'Formato de JSON incorrecto.'
        }), 500

    responsable = Responsable()

    try:
        responsable.tipo = form['tipo']
    except:
        pass
    try:
        responsable.nombre = form['nombre']
    except:
        pass
    try:
        responsable.telefono = form['telefono']
    except:
        pass

    try:
        for rec_id in form['recursos']:
            recurso = Recurso.get_by_id(db.session, rec_id)
            if recurso is not None:
                responsable.add_recurso(recurso)
    except:
        pass

    try:
        db.session.add(responsable)
        db.session.commit()
    except:
        db.session.rollback()
        return json.dumps({'success': False, 'error': 'Error guardando.'}), 500

    return json.dumps({
        'success': True,
        'message': 'Responsable agregado.'
    }), 200
Beispiel #4
0
def recurso_actualizar():

    try:
        form = json.loads(request.data)
    except json.JSONDecodeError:
        return json.dumps({
            'success': False,
            'error': 'Formato de JSON incorrecto.'
        }), 500

    try:
        recurso = Recurso.get_by_id(db.session, form['id'])
    except KeyError:
        recurso = None

    if recurso is None:
        return json.dumps({
            'success': False,
            'error': 'Recurso no encontrado.'
        }), 500

    try:
        recurso.serial = form['serial']
    except:
        json.dumps({'success': False, 'error': 'Error de serial.'}), 500
    try:
        recurso.marca = form['marca']
    except:
        pass
    try:
        recurso.proveedor = form['proveedor']
    except:
        pass
    try:
        recurso.valor_comercial = form['valor_comercial']
    except:
        pass
    try:
        recurso.fecha_compra = form['fecha_compra']
    except:
        pass
    try:
        recurso.estado = form['estado']
    except:
        pass
    try:
        recurso.remove_responsables()
        for r_id in form['responsables']:
            resp = Responsable.get_by_id(db.session, r_id)
            if resp is not None:
                recurso.add_responsable(resp)
    except:
        pass

    try:
        db.session.commit()
    except:
        db.session.rollback()
        return jsonify({'success': False, 'error': 'Error guardando.'}), 500

    return json.dumps({
        'success': True,
        'message': 'Recurso actualizado.'
    }), 200