Description:
PageContract is a zope product focused on making validation easy and secure. it differs from Formulator mainly in that it doesn't treat forms as objects and doesn't mess with the ui of the form. PageContract, IMO, is form validation with out the bs.
#assuming the following is in a python script
from Products.PageContract.Scripts import compile
metadata_upload_contract = """
#parameters
metadata_file:optional,file
metadata_format:constraint(supported_formats)
"""
contract = compile(metadata_upload_contract)
contract.validate(context)
Explanation:
this python script looks for two request variables metadata_file and metadata_format, it makes sure that metadata_format is in the values defined by the acquirable property support_formats and checks to make sure that if metadata_file is present in the request it is a file like object. if there are errors page_contract will in this case use the default error handler which will print the names and problem with the input variables, custom error handlers are easily specificed on a global per contract basis or per variable.
page contract has a lot more features than the ones listed here (multiple filters, filter args, filter groups, compilation caching, multiple error handlers, optional error handling). its also useable from dtml, python scripts, and python products, and is easy to extend.
Comments:
...and PageContract is located at: by limi - 2004-10-14