SQLFORM.grid search with fields readable = False

118 views
Skip to first unread message

cdbaron

unread,
Oct 26, 2019, 4:24:01 PM10/26/19
to web2py-users
Hello,

I have an SQLFROM.grid in which I render each of the lines with a special
format using only the id field of the table (id.represent). Attached image
with the result.

Everything works perfect except when searching records. The issue is that
hidden fields (readable = False) are excluded from the search.

This is the code in sqlhtml.py that that blocks the search

             sfields = reduce (lambda a, b: a + b,
                             
[[f for f in t if f.readable and f.searchable] for t in tables])

Why fields are excluded with readable = False if searchable = False exists?

Any way to search across all fields of the sql query?


regards.

Captura.JPG

cdbaron

unread,
Oct 30, 2019, 5:37:12 PM10/30/19
to web2py-users
This is my code

def federados():

    # Tablas de la BBDD
    t_licencias = db.t_licencias
    t_licencias_agrupaciones = db.t_licencias_agrupaciones
    t_federados = db.t_federados

    # Campos del grid
    fields = [
        t_federados.id,
        t_federados.f_foto,
        t_federados.f_fecha_nacimiento,
        t_federados.f_dni,
        t_federados.f_pasaporte,
        t_federados.f_nombre,
        t_federados.f_apellido1,
        t_federados.f_apellido2,
        t_federados.f_nacionalidad,
        t_federados.f_direccion,
        t_federados.f_poblacion,
        t_federados.f_provincia,
        t_federados.f_pais,
        t_federados.f_codigo_postal,
        t_federados.f_telefono_fijo,
        t_federados.f_telefono_movil,
        t_federados.f_email,
    ]

    # Campos ocultos
    t_federados.f_foto.readable = False
    t_federados.f_fecha_nacimiento.readable = False
    t_federados.f_dni.readable = False
    t_federados.f_pasaporte.readable = False
    t_federados.f_nombre.readable = False
    t_federados.f_apellido1.readable = False
    t_federados.f_apellido2.readable = False
    t_federados.f_nacionalidad.readable = False
    t_federados.f_direccion.readable = False
    t_federados.f_poblacion.readable = False
    t_federados.f_provincia.readable = False
    t_federados.f_pais.readable = False
    t_federados.f_codigo_postal.readable = False
    t_federados.f_telefono_fijo.readable = False
    t_federados.f_telefono_movil.readable = False
    t_federados.f_email.readable = False

    def represent_federado(f, r):

        represent = DIV(_class="row")

        nacimiento = Fechas.nacimiento_edad(r.f_fecha_nacimiento)
        nombre = f'{r.f_apellido1} {r.f_apellido2}, {r.f_nombre}'

        # foto
        represent.insert(0, IMG(_height='100', _width='75', _class='grid-foto m-1',
                                _src=URL(c='federados', f='download', args=r.f_foto)))

        represent.append(CAT(
            DIV(
                DIV(nombre), DIV(r.f_dni), DIV(r.f_nacionalidad), DIV(nacimiento),
                _class='grid-datos-federado m-1'),
            ))

        represent.append(CAT(
            DIV(
                DIV(r.f_telefono_fijo), DIV(r.f_telefono_movil), DIV(r.f_email),
                _class='grid-datos-federado m-1'),
            ))

        return represent

   
    id_entidad = auth.user.f_id_entidad

    query = (t_licencias.f_id_entidad == id_entidad) & \
            (t_licencias_agrupaciones.f_id_temporada == temporada_actual.id)

    left = [
        t_licencias_agrupaciones.on((t_licencias_agrupaciones.f_id_federado == t_federados.id)),
        t_licencias.on(t_licencias.f_id_agrupacion == t_licencias_agrupaciones.id),
    ]

    groupby = [t_licencias_agrupaciones.f_id_federado]
    orderby = [t_federados.f_apellido1, t_federados.f_apellido2, t_federados.f_nombre]
   
    t_federados.id.represent = lambda f, r: represent_federado(f, r)
    t_federados.id.label = T('Datos de los federados')

    grid = SQLFORM.grid(query,
                        fields=fields,
                        field_id=db.t_federados.id,
                        left=left,
                        groupby=groupby,
                        orderby=orderby,
                        paginate=10,
                        advanced_search=False,
                        deletable=False,
                        editable=False,
                        details=False,
                        create=False,
                        csv=False)

    return dict(grid=grid)

 

Paul Ellis

unread,
Nov 1, 2019, 11:52:04 AM11/1/19
to web2py-users
If you want the fields to be searchable. Then instead of setting readable = false.

Hide the fields with:

db.table.field.represent = lambda value, row: DIV(value, _class='hidden')

and the column heading with:

grid = SQLFORM.grid(
    headers
= {
         
'table.field' : DIV(_style = "display:None"),
       
}
   
)


cdbaron

unread,
Nov 4, 2019, 5:50:50 PM11/4/19
to web...@googlegroups.com
It works,

but the solution is db.table.field.listable = False to hide fields in the grid and search, db.table.field.readable = False to hide fields and not search and db.table.field.searchable = False to show Fields in grid and not search.
Reply all
Reply to author
Forward
0 new messages