Search code examples
pythonweb2py

GET search in multilanguage site


I've included a search form in my web2py application, in the following form:

myapp/controller/search?query=myquery

However, for security reasons web2py automatically replaces spaces and non-alphanumeric characters with underscores, which is okay for English-only sites but an impediment for languages that use accent marks. For example, searching for "áéíóú" returns five underscores.

This could be solved by using POST instead of GET for the search form, but then the users wouldn't be able to bookmark the results.

Is there any option to solve this?

Thanks in advance.


Solution

  • Here's an idea that I've used in the past:

    1. Use post to submit the query
    2. Generate a unique string (e.g. youtube: https://www.youtube.com/watch?v=jX3DuS2Ak3g)
    3. Associate the query to that string and store as key/value pair in session/app state/db (depending on how long you want it to live)
    4. Redirect the user to that

    If you don't want to occupy extra memory/space as they tend to grow a lot in some cases, you can substitute steps 2-3 with encrypting the string to something you can decrypt afterwards. You can do this in a middleware class so that it's transparent to your app's logic.