def get_proyectos(id):
    utilidades.permitir_CORS()
    SQL = """
          SELECT id,
                 descripcion,
                 estado,
                 responsable,
                 fecha_peticion,
                 fecha_inicio,
                 fecha_fin
            FROM proyectos
           WHERE id = ?
        ORDER BY id,
                 descripcion
          """

    registros = []
    cursor.execute(SQL, (id,))
    fila = cursor.fetchone()
    if fila:
        columnas = [columna[0] for columna in cursor.description]
        registros.append(utilidades.fila_a_diccionario(columnas, fila))

    if registros:
        return {'status': 'OK', 'mensajes': ['Selección realizada con éxito'], 'datos': registros}        
    else:
        return {'status': 'OK', 'mensajes': ['No existen registros para la selección'], 'datos': registros}
Example #2
0
def post_OT():
    utilidades.permitir_CORS()
    datos_json = request.body.read()
    if not datos_json:
        abort(400, 'NO se recibieron datos')
    else:
        objeto_datos = json.loads(datos_json.decode("utf-8"))
        if not 'ot'          in objeto_datos          or \
           not 'descripcion' in objeto_datos          or \
           not 'tipo'        in objeto_datos          or \
           not 'orden'       in objeto_datos:
            abort(400, 'NO se especificaron todos los datos')
        else:
            try:
                if not 'ultimo_transporte' in objeto_datos or objeto_datos[
                        'ultimo_transporte'] == '':
                    cursor.execute("INSERT INTO ordenes (ot, descripcion, tipo, orden) VALUES (?, ?, ?, ?)", \
                                (objeto_datos['ot'],          \
                                objeto_datos['descripcion'], \
                                objeto_datos['tipo'],        \
                                objeto_datos['orden']))
                else:
                    cursor.execute("INSERT INTO ordenes (ot, descripcion, tipo, orden, ultimo_transporte) VALUES (?, ?, ?, ?, ?)", \
                                (objeto_datos['ot'],          \
                                objeto_datos['descripcion'], \
                                objeto_datos['tipo'],        \
                                objeto_datos['orden'],
                                datetime.datetime.fromtimestamp(time.mktime(time.strptime(objeto_datos['ultimo_transporte'], "%Y-%m-%dT%H:%M:%S.%fZ")))
                                ))
                conexion.commit()

            except sqlite3.Error as err:
                abort(400, 'ERROR al insertar datos')

        return json.dumps({'status': 200, 'mensaje': 'OK'})
Example #3
0
def get_qry(qry):
    utilidades.permitir_CORS()
    SQL = """
          SELECT ot,
                 descripcion,
                 tipo,
                 orden,
                 ultimo_transporte
            FROM ordenes
           WHERE 1 = 1
          """

    datos_json = qry
    objeto_datos = json.loads(datos_json.decode("utf-8"))
    if 'descripcionLike' in objeto_datos:
        SQL = SQL + " AND descripcion LIKE '%" + objeto_datos[
            'descripcionLike'] + "%' "
    if 'tipoEq' in objeto_datos:
        SQL = SQL + " AND tipo = '" + objeto_datos['tipoEq'] + "' "

    registros = []
    for fila in cursor.execute(SQL):
        columnas = ("ot", "descripcion", "tipo", "orden", "ultimo_transporte")
        registros.append(utilidades.fila_a_diccionario(columnas, fila))

    if registros:
        return json.dumps(registros)
    else:
        abort(404, 'No esixte el recurso')
def put_proyectos():
    utilidades.permitir_CORS()
    datos_json = request.body.read()
    if not datos_json:
        return {'status': 'KO', 'mensajes': ['No ha proporcionado datos. '], 'datos': []}
    else:
        objeto_datos = json.loads(datos_json.decode("utf-8"))
        if  (not objeto_datos['id']          or objeto_datos['id']          == '' or 
                not objeto_datos['descripcion'] or objeto_datos['descripcion'] == ''):
            return {'status': 'KO', 'mensajes': ['Faltan datos obligatorios. '], 'datos': []}
        else:
            try:
                SQLcol = "UPDATE proyectos SET id = ?, descripcion = ?"
                SQLfin = " WHERE id = ?"
                valores = [objeto_datos['id'],objeto_datos['descripcion']]
                if 'estado' in objeto_datos:
                    SQLcol += ", estado = ?"
                    if objeto_datos['estado']:
                        valores.append(objeto_datos['estado'])
                    else:
                        valores.append(None)
                if 'responsable' in objeto_datos:
                    SQLcol += ", responsable = ?"
                    if objeto_datos['responsable']:
                        valores.append(objeto_datos['responsable'])
                    else:
                        valores.append(None)
                if 'fecha_peticion' in objeto_datos:
                    SQLcol += ", fecha_peticion = ?"
                    if objeto_datos['fecha_peticion']:
                        valores.append(datetime.datetime.fromtimestamp(time.mktime(time.strptime(objeto_datos['fecha_peticion'], "%Y-%m-%d"))))
                    else:
                        valores.append(None)
                if 'fecha_inicio' in objeto_datos:
                    SQLcol += ", fecha_inicio = ?"
                    if objeto_datos['fecha_inicio']:
                        valores.append(datetime.datetime.fromtimestamp(time.mktime(time.strptime(objeto_datos['fecha_inicio'], "%Y-%m-%d"))))
                    else:
                        valores.append(None)
                if 'fecha_fin' in objeto_datos:
                    SQLcol += ", fecha_fin = ?"
                    if objeto_datos['fecha_fin']:
                        valores.append(datetime.datetime.fromtimestamp(time.mktime(time.strptime(objeto_datos['fecha_fin'], "%Y-%m-%d"))))
                    else:
                        valores.append(None)

                valores.append(objeto_datos['id'])

                SQL = SQLcol + SQLfin
                cursor.execute(SQL, valores)
                conexion.commit()

            except sqlite3.Error as err:
                return {'status': 'KO', 'mensajes': ['ERROR SQL al modificar los datos.', err.args[0]], 'datos': []}

        return {'status': 'OK', 'mensajes': ['Registro modificado correctamente.'], 'datos': []}
Example #5
0
def get_OTs():
    utilidades.permitir_CORS()
    registros = []
    for fila in cursor.execute("SELECT * FROM ordenes"):
        columnas = ("ot", "descripcion", "tipo", "orden", "ultimo_transporte")
        registros.append(utilidades.fila_a_diccionario(columnas, fila))

    if registros:
        return json.dumps(registros)
    else:
        abort(404, 'No esixte el recurso')
Example #6
0
def delete_OT(ot):
    utilidades.permitir_CORS()
    try:
        cursor.execute("DELETE FROM ordenes WHERE ot = ?", (ot, ))
        conexion.commit()
        if cursor.rowcount == 0:
            abort(404, 'ERROR al borrar registro')

    except sqlite3.Error as err:
        abort(400, 'ERROR al borrar registro')

    return json.dumps({'status': 200, 'mensaje': 'OK'})
def delete_proyectos(id):
    utilidades.permitir_CORS()
    try:
       cursor.execute("DELETE FROM proyectos WHERE id = ?", (id, ))
       conexion.commit()
       if cursor.rowcount == 0:
          abort(404, 'ERROR al borrar registro')

    except sqlite3.Error as err:
       return {'status': 'KO', 'mensajes': ['ERROR SQL al insertar los datos.', err.args[0]], 'datos': []}

    return {'status': 'OK', 'mensajes': ['Registro borrado'], 'datos': []}
Example #8
0
def put_OT():
    utilidades.permitir_CORS()
    datos_json = request.body.read()
    if not datos_json:
        abort(400, 'NO se recibieron datos')
    else:
        objeto_datos = json.loads(datos_json.decode("utf-8"))
        if not 'ot' in objeto_datos:
            abort(400, 'NO se especificaron todos los datos')
        else:
            campos = []
            valores = []
            campo_clave = 'ot'
            campo_fecha = 'ultimo_transporte'
            for atributo in objeto_datos:
                if atributo != campo_clave:
                    if atributo == campo_fecha:
                        valores.append(
                            datetime.datetime.fromtimestamp(
                                time.mktime(
                                    time.strptime(
                                        objeto_datos['ultimo_transporte'],
                                        "%Y-%m-%dT%H:%M:%S.%fZ"))))
                    else:
                        valores.append(objeto_datos[atributo])
                    campos.append(atributo + ' = ?')

            if len(campos):
                valores.append(objeto_datos[campo_clave])
                lista_campos = "SET " + ', '.join(campos)
                SQL = " UPDATE ordenes " + lista_campos + " WHERE ot = ?"
                try:
                    cursor.execute(SQL, tuple(valores))
                    conexion.commit()
                    if cursor.rowcount == 0:
                        abort(400, 'ERROR al actualizar datos')

                except sqlite3.Error as err:
                    abort(400, 'ERROR al actualizar datos')
            else:
                abort(400, 'ERROR al actualizar datos')

    return json.dumps({'status': 200, 'mensaje': 'OK'})
Example #9
0
def get_user_roles():
    utilidades.permitir_CORS()
    registros = []

    for fila in cursor.execute("SELECT rol FROM roles WHERE usuario = ?",
                               (request.query.token, )):
        registros.append(fila[0])

    if registros:
        return json.dumps({
            "code": 20000,
            "data": {
                "name": request.query.token,
                "avatar": "",
                "role": registros
            }
        })
    else:
        abort(404, 'No esixte el recurso')
Example #10
0
def get_OT(ot):
    utilidades.permitir_CORS()
    SQL = """
          SELECT ot,
                 descripcion,
                 tipo,
                 orden,
                 ultimo_transporte
            FROM ordenes
           WHERE ot = ?
        ORDER BY ot,
                 descripcion
          """

    cursor.execute(SQL, (ot, ))
    fila = cursor.fetchone()
    columnas = ("ot", "descripcion", "tipo", "orden", "ultimo_transporte")
    if fila:
        return json.dumps(utilidades.fila_a_diccionario(columnas, fila))
    else:
        abort(404, 'No esixte el recurso')
def get_qry(qry):
    utilidades.permitir_CORS()
    SQL = """
          SELECT id,
                 descripcion,
                 estado,
                 responsable,
                 fecha_peticion,
                 fecha_inicio,
                 fecha_fin
            FROM proyectos
           WHERE 1 = 1
          """

    datos_json = qry
    objeto_datos = json.loads(datos_json.decode("utf-8"))
    if 'idEQ' in objeto_datos:
        SQL = SQL + " AND id = '" + objeto_datos['idEQ'] + "' "    
    if 'idGE' in objeto_datos:
        SQL = SQL + " AND id >= '" + objeto_datos['idGE'] + "' "    
    if 'idLE' in objeto_datos:
        SQL = SQL + " AND id <= '" + objeto_datos['idLE'] + "' "    
    if 'idLIKE' in objeto_datos:
        SQL = SQL + " AND id LIKE '%" + objeto_datos['idLIKE'] + "%' "    
    if 'descripcionLIKE' in objeto_datos:
        SQL = SQL + " AND descripcion LIKE '%" + objeto_datos['descripcionLIKE'] + "%' "    
    
    SQL = SQL + " ORDER BY id, descripcion"

    registros = []
    for fila in cursor.execute(SQL):
        columnas = [columna[0] for columna in cursor.description]
        registros.append(utilidades.fila_a_diccionario(columnas, fila))

    if registros:
        return {'status': 'OK', 'mensajes': ['Selección realizada con éxito'], 'datos': registros}        
    else:
        return {'status': 'OK', 'mensajes': ['No existen registros para la selección'], 'datos': registros}
Example #12
0
def enable_CORS_OT(ot):
    utilidades.permitir_CORS()
    return json.dumps({'status': 200, 'mensaje': 'OK'})
Example #13
0
def post_user_logout():
    utilidades.permitir_CORS()
    return json.dumps({'code': 20000, 'data': {'token': 'admin'}})
def enable_CORS_proyectos(qry):
    utilidades.permitir_CORS()
    return {'status': 'OK', 'mensajes': ['OK'], 'datos': []}
def post_proyectos():
    utilidades.permitir_CORS()
    datos_json = request.body.read()
    if not datos_json:
        return {'status': 'KO', 'mensajes': ['No ha proporcionado datos. '], 'datos': []}
    else:
        objeto_datos = json.loads(datos_json.decode("utf-8"))
        if not 'id'          in objeto_datos   or \
           not 'descripcion' in objeto_datos:
           return {'status': 'KO', 'mensajes': ['Faltan datos obligatorios. '], 'datos': []}
        else:
            if  (not objeto_datos['id']          or objeto_datos['id']          == '' or 
                 not objeto_datos['descripcion'] or objeto_datos['descripcion'] == ''):
                return {'status': 'KO', 'mensajes': ['Faltan datos obligatorios. '], 'datos': []}
            try:
                SQLcol = "INSERT INTO proyectos (id, descripcion"
                SQLval = ") VALUES (?, ?"
                valores = [objeto_datos['id'],objeto_datos['descripcion']]
                if 'estado' in objeto_datos:
                    SQLcol += ", estado"
                    SQLval += ", ?"
                    if objeto_datos['estado']:
                        valores.append(objeto_datos['estado'])
                    else:
                        valores.append(None)
                if 'responsable' in objeto_datos:
                    SQLcol += ", responsable"
                    SQLval += ", ?"
                    if objeto_datos['responsable']:
                        valores.append(objeto_datos['responsable'])
                    else:
                        valores.append(None)
                if 'fecha_peticion' in objeto_datos:
                    SQLcol += ", fecha_peticion"
                    SQLval += ", ?"
                    if objeto_datos['fecha_peticion']:
                        valores.append(datetime.datetime.fromtimestamp(time.mktime(time.strptime(objeto_datos['fecha_peticion'], "%Y-%m-%d"))))
                    else:
                        valores.append(None)
                if 'fecha_inicio' in objeto_datos:
                    SQLcol += ", fecha_inicio"
                    SQLval += ", ?"
                    if objeto_datos['fecha_inicio']:
                        valores.append(datetime.datetime.fromtimestamp(time.mktime(time.strptime(objeto_datos['fecha_inicio'], "%Y-%m-%d"))))
                    else:
                        valores.append(None)
                if 'fecha_fin' in objeto_datos:
                    SQLcol += ", fecha_fin"
                    SQLval += ", ?"
                    if objeto_datos['fecha_fin']:
                        valores.append(datetime.datetime.fromtimestamp(time.mktime(time.strptime(objeto_datos['fecha_fin'], "%Y-%m-%d"))))
                    else:
                        valores.append(None)

                SQL = SQLcol + SQLval + ")"
                cursor.execute(SQL, valores)
                conexion.commit()

            except sqlite3.Error as err:
                return {'status': 'KO', 'mensajes': ['ERROR SQL al insertar los datos.', err.args[0]], 'datos': []}

        return {'status': 'OK', 'mensajes': ['Registro insertado correctamente.'], 'datos': []}