[Zope] Upload file and :int with :required and

Dieter Maurer dieter@handshake.de
Mon, 22 Jan 2001 23:14:56 +0100 (CET)


Diego Rodrigo Neufert writes:
 > When using :required with a file field I got this error:
 > Error Type: AttributeError
 > Error Value: 'string' object has no attribute 'read'
 > 
 > How to make a file field required in dtml?
 > 
 > and anyone know how to make something like :int:required works?
 > I need a int field to be required....
Both will not work.

":required" is implemented as a converter (which is a bug, in my view).
It means "convert to a string and check, it is not whitespace only".

":int" is a converter, too. And you can only have a single converter
per form variable.
However, ":int" implies "required", as an empty string is not
a valid integer. This means you will get a ValueError, if the
form field is submitted empty, unless you used he ":ingore_empty"
suffix.

To check that a file was supplied, you can check *in DTML* that
"<file>.filename" is non_empty:

  <dtml-unless "your_file_field.filename">
     <!-- raise an error -->
  </dtml-in>


Dieter