Module lemon.html.fields
HTML Fields
The idea is that you can create field values in a standard way and then
you derive a form from the form class to look and behave exactly as you want your form to
behave with your own validation, export, import functions etc. Use a class for each field in the form.
See the doc/examples/code/forms.py example and all will become transparently clear
Developer Ideas
===============
It doesn't matter what the fields do internally but they must expose the following interface:
TIP: It isn't really worth trying to maintain complex data types inside the classes because often the values
come back as strings and your class may expect integers, doing a conversion could lead to an error before the
validation is done and just cause problems. It works out easier just to get the string values from the fields,
maintain them as a list of values and then convert them in the valid() funciton where you can let the user know
if things go wrong. This means clever inheritance is nearly impossible but will proabably save you any hassle.
builderValue() is for other applications to get the final value.
New Ideas
---------
Internally the fields keep their values as string representations. These values are set ant retrieved using the
set() and get() methods. Fields taking multiple values are kept as an array of strings.
An empty string is treated as a NULL value for single fields. An empty array is treated as NULL for multiple
fields.
The populate() method is used to retrieve information from a dictionary (such as a cgi.FieldStorage() and populate
the field with the appropriate string representation value using the set() method. This way fields don't have to
have make sure that they submit their string representation when a user clicks submit.
The retrieve() method is used in derived classes to convert from the string representation to a representation
suitatble for the value being represented.
Derived Classes
---------------
Derived from the base classes should be fields with types. For example integer fields, multiple time fields, date
fields etc. These should implement the retrieve() method explained above and the populate() method should also
accept the value output by retrieve().
Attribute Access
----------------
All classes should have private member variables with get() and set() methods. Attribute access should then be
emulated by overriding the __getattr__ () methods. This leads to robust code and a simple interface between the
variables exposed to the user and the actual variables required.
__author__
-
- Type:
-
str
- Value:
'James Gardner <james@xecos.com>'
|
|
__credits__
-
- Type:
-
str
- Value:
'Guido van Rossum, for an excellent programming language.'
|
|
__date__
-
- Type:
-
str
- Value:
|
__version__
-
- Type:
-
str
- Value:
|