con2 / kompassi

Kompassi Event Management System
https://kompassi.eu
Other
26 stars 27 forks source link

In addition to `process_form_data`, should we have its reverse `values_to_form_data`? #440

Open japsu opened 6 months ago

japsu commented 6 months ago

The idea of form_data vs. values is to store whatever the user's browser sent in form_data and only convert it on demand to values. form_data is always* dict[str, str] whereas values can be dict[str, str | int | list[str] | dict[str, str]] or even more types.

Currently SchemaFormInput is responsible for understanding the values type of its value (eg. DateTimeField: ISO 8601 string #438, NumberField: number etc.) and making whatever conversion is required to enable an <input> to display it.

Should this conversion be pushed to the backend, or should we expose the raw Response.form_data so that field implementation would be more straightforward <input type={type} value={value}>?

The form_data -> values -> form_data conversion cycle may still be preferred in order to perform satanization.

*) Actually not true due to FileUploadField value in form_data always being list[str] regardless of number of files. So we are already touching the form_data in frontend before it reaches the databae.