When committing data that has originally come from a webpage, sometimes data has to be converted to a data type or format which is suitable for the back-end database. For instance, a date in 'dd/mm/yyyy' format needs to be converted to a Python date-object or 'yyyy-mm-dd' in order to be stored in a SQLite date column (SQLite will accept 'dd/mm/yyyy', but that can cause problems when data is retrieved).
Question - at what point should the data be converted? a) As part of a generic web_page_save() method (immediately after data validation, but before a row.table_update() method is called). b) As part of row.table_update() (a data-object method called from web- or non-web-based applications, and includes construction of a field-value parameter list prior to executing the UPDATE command).
In other words, from a framework point-of-view, does the data-conversion belong to page-object processing or data-object processing?
Any opinions would be appreciated.
Alan
2 Answers 2
I think it belongs in the validation. You want a date, but the web page inputs strings only, so the validator needs to check if the value van be converted to a date, and from that point on your application should process it like a date.
Comments
I could be wrong, but I think there is no definite answer to this question. It depends on "language" level your framework provides. For example, if another parts of the framework accept data in non-canonical form and then convert it to an internal canonical form, it this case it would worth to support some input date formats that are expected.
I always prefer to build strict frameworks and convert data in front-ends.