4GL Patterns #5 – Field Filters
Thursday, 18 September 2008
I have encountered this pattern twice. Once in CodeIgniter, and another time in Django.
The basic idea is to pipe values through a series of filters before it is displayed in the presentation layer, or before it is saved in the database. These filters, if stored in a schema definition, can be applied globally to an application, minimizing rework when the rules change.
These filters could also be applied in the text converter pattern, so that user knows that values will be transformed before they are serialized.
For example:
Presentation layer: {{ name | titlecase }}
Before updating database: user_id | lower | trim_to_maxlength[50]
You should follow me on twitter here