__init__.py
changeset 8556 bbe0d6985e59
parent 8486 399e916a97f3
child 8594 001159e2e4f3
equal deleted inserted replaced
8555:c747242d22a6 8556:bbe0d6985e59
   197     """
   197     """
   198     def _decorator(func):
   198     def _decorator(func):
   199         CW_EVENT_MANAGER.bind(event, func, *args, **kwargs)
   199         CW_EVENT_MANAGER.bind(event, func, *args, **kwargs)
   200         return func
   200         return func
   201     return _decorator
   201     return _decorator
       
   202 
       
   203 
       
   204 from yams.schema import role_name as rname
       
   205 
       
   206 def validation_error(entity, errors, substitutions=None, i18nvalues=None):
       
   207     """easy way to retrieve a :class:`cubicweb.ValidationError` for an entity or eid.
       
   208 
       
   209     You may also have 2-tuple as error keys, :func:`yams.role_name` will be
       
   210     called automatically for them.
       
   211 
       
   212     Messages in errors **should not be translated yet**, though marked for
       
   213     internationalization. You may give an additional substition dictionary that
       
   214     will be used for interpolation after the translation.
       
   215     """
       
   216     if substitutions is None:
       
   217         # set empty dict else translation won't be done for backward
       
   218         # compatibility reason (see ValidationError.tr method)
       
   219         substitutions = {}
       
   220     for key in errors.keys():
       
   221         if isinstance(key, tuple):
       
   222             errors[rname(*key)] = errors.pop(key)
       
   223     return ValidationError(getattr(entity, 'eid', entity), errors,
       
   224                            substitutions, i18nvalues)