Hi Ben, > Is there a way to have storm do the type coercion automatically when I > try to set an attribute? Example: (...)
You can easily implement something like this yourself, but arbitrary type coercion isn't done by Storm itself by design. > building up a list (ie from a <form> submit), I have to first check > for safe input, then coerce from str to int, or unicode etc. Which > means that the methods I use to sanitize form input and put it in the > database have to know/care what type storm expects. The task of ensuring that user-provided text is actually valid input for your model should indeed be done by your application for a number of reasons. Storm supports a "validator" argument on its properties to help you with that. The argument passed in is a function which is called like validator(object, attr, value), and you can either raise an exception out of it, or process the value and return the real value that is supposed to be used on the attribute. We can definitely provide helpers at some point like maximum size and whatnot, but coercion of form data and application-level validation goes way beyond that. -- Gustavo Niemeyer http://niemeyer.net -- storm mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/storm
