Let me explain one of the problems from decoupling forms from their
HTML representation.

data has different representations depending on its status in the
system. For example in a submitted mime multipart form a file is a
FieldStorage object with a file and a filename attribute. A file in
Python is just an object with read/write methods. A file in the DAL is
just a temporary name into a Field(...'upload') and the data is stored
somewhere else, usually on the filesystem, perhaps in a Field
(...'blob').

A validator is an object that takes the data in a form format and
converts it into DAL format. It fails to convert, it modifies the HTML
form to include error messages.

Think for example of the IS_IMAGE validator. It acts on a FieldStorage
object.

Think also about error messages. Currently they do not have to be
strings. They can be helpers. They can contain links or other
structure.

Validators are two-way filters. Think about IS_DATE. It converts a
date from the string representation choose for the HTML form into
datetime.date format used by the DAL and vice versa when the data is
extracted from the DAL and put into an update form.

Validators since they are filters can be piped.

The all process is designed to take an HTML form, validate it, convert
it, store the data in DAL or return a different form with errors.

Breaking this process in two layers (an abstract form and a form
representation) would require decoupling the role of validation from
the role of converting the data. This is logically complicated. This
may also be practically complicated for the user.

This the reason why so far we have been unable to validate
import_from_csv_file since you cannot use validators for that purpose.

Web2py was designed with the 80-20 rule in mind: make it easy in the
80% of the cases at the expense of making more complex in the 20% of
the cases. You can make things easy for that 20% at the expense of
making things more complex in the other 80% but I do not think that is
what we want.

Anyway, I do think the current system can be improved and made more
general. I do not see how this decoupling can be done. Perhaps it is
just me. I will be happy to see proposals.

Massimo
-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.


Reply via email to