About encoding url vars. Now in the grid searches

131 views
Skip to first unread message

CarlosDB

unread,
Jun 18, 2022, 2:18:18 PM6/18/22
to py4web

Seems to be related to this issue, https://groups.google.com/g/py4web/c/-V7fYJL7S44

Using the "search_queries" option, searches containing special characters such as ñ or accented letters used in Spanish do not work.

When pressing the search button strange characters appear and each time the button is pressed more and more characters appear.

A code example:


db.define_table(
    't_test_grid',
    Field('f_test1', 'string', length=30),
)
db.commit()

if not db(db.t_test_grid).select():
    db.t_test_grid.insert(f_test1='niña')
    db.t_test_grid.insert(f_test1='niño')
    db.t_test_grid.insert(f_test1='camión')
    db.t_test_grid.insert(f_test1='cigüeña')

db.commit()

@action('grid_test')
@action('grid_test/<path:path>')
@action.uses('grid_test.html', db)
def grid_test(path=None):

    t_test_grid = db.t_test_grid
    grid = Grid(
        path=path,
        query=t_test_grid,
        search_queries=[
            ('Test', lambda value: t_test_grid.f_test1.contains(value)),
        ],
        rows_per_page=10,
    )

    return dict(grid=grid)

CarlosDB

unread,
Jun 21, 2022, 5:03:27 AM6/21/22
to py4web
In the file grid.py lines 492 and 839 changing

search_string = request.query.get("search_string")
by
search_string = request.query.getunicode("search_string")

solves the problemna, but I don't know if it is the best solution.

Carlos.

Massimo

unread,
Jun 25, 2022, 1:50:35 PM6/25/22
to py4web
I think py4web should monkeypatch bottle and umbott so that get is getunicode and getbytes is get. Any objection?

CarlosDB

unread,
Jun 27, 2022, 12:11:33 PM6/27/22
to py4web

Another similar problem this time with the response header.

Looks like it’s coming from ombott/response.py line 159

Small simplified example:

@authenticated('download_document', method=['GET'])
def download_document():

    document_pdf = get_document()

    response.headers['Content-Type'] = 'application/pdf'
    response.headers['Content-Disposition'] = f'attachment; filename=información.pdf'
    return document_pdf

The file is downloaded with this name, información.pdf

Val K

unread,
Jun 27, 2022, 3:42:52 PM6/27/22
to py4web
Please google a little 
понедельник, 27 июня 2022 г. в 19:11:33 UTC+3, CarlosDB:

CarlosDB

unread,
Jun 27, 2022, 3:48:36 PM6/27/22
to py4web
Thanks.

I am migrating a web2py application and it was working perfectly just like in the example. I guess web2py was doing its magic.

Val K

unread,
Jun 27, 2022, 4:06:40 PM6/27/22
to py4web
Its very strange as i dont see in web2py code filename encoding

понедельник, 27 июня 2022 г. в 22:48:36 UTC+3, CarlosDB:

CarlosDB

unread,
Jun 27, 2022, 4:52:26 PM6/27/22
to py4web
I'm going to look at it carefully.
I have several web2py applications that generate and download pdf documents and I have never encountered any problems with non US-ASCII filenames.

Val K

unread,
Jun 27, 2022, 7:05:08 PM6/27/22
to py4web
Magic happens (if it happens) on the client side - smart browser and/or OS, which can recognize unspecified encoding
Use tool that doesnt do any fixup  (e.g. requests)  to see real situation

понедельник, 27 июня 2022 г. в 23:52:26 UTC+3, CarlosDB:

CarlosDB

unread,
Jun 29, 2022, 6:48:15 AM6/29/22
to py4web
ok, it's clear that the magic of web2py is that there is no magic, what is put in the response arrives unchanged to the client.

I'm sorry I mixed up two different topics.

The important thing is the topic is at the beginning of the thread, right now the search functionality of the grid is a bit broken, depending on the words that are searched  (accented letters, the letter ñ and other special characters) the search does not work and I don't know what could be the best solution.

This problem limits the use of the application depending on the language.


Carlos.

Massimo

unread,
Jun 30, 2022, 2:40:16 AM6/30/22
to py4web
I posted (master) a possible monkey patch solution but notice that now request.query.get("key") and request.query["key"] do not return the same value. Need to think about this some more.

CarlosDB

unread,
Jun 30, 2022, 10:50:35 AM6/30/22
to py4web
Thank you Massimo.

It works well.
Reply all
Reply to author
Forward
0 new messages