Coder Social home page Coder Social logo

Comments (3)

simonw avatar simonw commented on June 22, 2024

I found this problem while trying to use WTForms with this pattern:

choices = [(col, col) for col in await db.table_columns(table)]

class ConfigForm(Form):
    template = TextAreaField("Template")
    api_token = PasswordField("OpenAI API token")
    columns = MultiCheckboxField('Columns', choices=choices)

from datasette.

simonw avatar simonw commented on June 22, 2024

It should return a MultiParams:

class MultiParams:
def __init__(self, data):
# data is a dictionary of key => [list, of, values] or a list of [["key", "value"]] pairs
if isinstance(data, dict):
for key in data:
assert isinstance(
data[key], (list, tuple)
), "dictionary data should be a dictionary of key => [list]"
self._data = data
elif isinstance(data, list) or isinstance(data, tuple):
new_data = {}
for item in data:
assert (
isinstance(item, (list, tuple)) and len(item) == 2
), "list data should be a list of [key, value] pairs"
key, value = item
new_data.setdefault(key, []).append(value)
self._data = new_data

Change needs to be made before 1.0.

return MultiParams(urllib.parse.parse_qs(body.decode("utf-8")))

Need to remember why I was using keep_blank_values=True there and check that using MultiParams doesn't conflict with that reason.

from datasette.

simonw avatar simonw commented on June 22, 2024

That keep_blank_values=True is from 0934844

Commit message:

request.post_vars() no longer discards empty values

Relevant test:

async def receive():
return {
"type": "http.request",
"body": b"foo=bar&baz=1&empty=",
"more_body": False,
}
request = Request(scope, receive)
assert {"foo": "bar", "baz": "1", "empty": ""} == await request.post_vars()

from datasette.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.