Back to index

plone3  3.1.7
Classes | Functions | Variables
archetypes.kss.validation Namespace Reference

Classes

class  ValidationView
class  _marker

Functions

def validate

Variables

tuple SKIP_KSSVALIDATION_FIELDTYPES = ('image', 'file')
 missing_uid_deprecation = \

Class Documentation

class archetypes::kss::validation::_marker

Definition at line 108 of file validation.py.


Function Documentation

def archetypes.kss.validation.validate (   self,
  instance = None,
  REQUEST = None,
  errors = None,
  data = None,
  metadata = None,
  predicates = () 
)
Validate the state of the entire object.

The passed dictionary ``errors`` will be filled with human readable
error messages as values and the corresponding fields' names as
keys.

If a REQUEST object is present, validate the field values in the
REQUEST.  Otherwise, validate the values currently in the object.

Definition at line 112 of file validation.py.

00112 
00113              errors=None, data=None, metadata=None, predicates=()):
00114     """Validate the state of the entire object.
00115 
00116     The passed dictionary ``errors`` will be filled with human readable
00117     error messages as values and the corresponding fields' names as
00118     keys.
00119 
00120     If a REQUEST object is present, validate the field values in the
00121     REQUEST.  Otherwise, validate the values currently in the object.
00122     """
00123     if REQUEST:
00124         fieldset = REQUEST.form.get('fieldset', None)
00125     else:
00126         fieldset = None
00127     fields = []
00128 
00129     if fieldset is not None:
00130         schemata = instance.Schemata()
00131         fields = [(field.getName(), field)
00132                   for field in schemata[fieldset].fields() 
00133                       if not [pred for pred in predicates if not pred(field)]
00134                  ]
00135 
00136     else:
00137         if data:
00138             fields.extend([(field.getName(), field)
00139                            for field in self.filterFields(isMetadata=0, *predicates)])
00140         if metadata:
00141             fields.extend([(field.getName(), field)
00142                            for field in self.filterFields(isMetadata=1, *predicates)])
00143 
00144     if REQUEST:
00145         form = REQUEST.form
00146     else:
00147         form = None
00148     for name, field in fields:
00149         error = 0
00150         value = None
00151         widget = field.widget
00152         if form:
00153             result = widget.process_form(instance, field, form,
00154                                          empty_marker=_marker)
00155         else:
00156             result = None
00157         if result is None or result is _marker:
00158             accessor = field.getEditAccessor(instance) or field.getAccessor(instance)
00159             if accessor is not None:
00160                 value = accessor()
00161             else:
00162                 # can't get value to validate -- bail
00163                 continue
00164         else:
00165             value = result[0]
00166 
00167         res = field.validate(instance=instance,
00168                              value=value,
00169                              errors=errors,
00170                              REQUEST=REQUEST)
00171         if res:
00172             errors[field.getName()] = res
00173     return errors

Here is the caller graph for this function:


Variable Documentation

Definition at line 35 of file validation.py.

Definition at line 31 of file validation.py.