Commit c8f9be08 authored by Jérome Perrin's avatar Jérome Perrin

fix stx format for HelpSys



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14591 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b7478769
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
# #
############################################################################## ##############################################################################
"""Constraint Interface.
"""
try: try:
from Interface import Interface from Interface import Interface
except ImportError: except ImportError:
...@@ -41,33 +44,33 @@ class Constraint(Interface): ...@@ -41,33 +44,33 @@ class Constraint(Interface):
A property sheet can contain _constraints slot ( just like _properties and A property sheet can contain _constraints slot ( just like _properties and
_categories ). _constraints is a list of constraint definition represented _categories ). _constraints is a list of constraint definition represented
as dictionnaries, for example we can have: as dictionnaries, for example we can have::
_constraints = ( _constraints = (
{ # we need to have an id { # we need to have an id
'id': 'the_constraint', 'id': 'the_constraint',
# Specify the class name of the constraint. The class name must be
# registered to ERP5Type. If the class is not found, a
# ConstraintNotFound error will be raised when trying to use it.
'type': 'MyConstraintClass',
# Specify the class name of the constraint. The class name must be # Constraint have a description.
# registered to ERP5Type. If the class is not found, a 'description': 'Constraint description',
# ConstraintNotFound error will be raised when trying to use it.
'type': 'MyConstraintClass', # XXX condition is a TALES Expression; is it part of the API ?
# how to use condition based on a workflow state in a workflow before
# Constraint have a description. # script, where the document is not in that state yet ?
'description': 'Constraint description', 'condition': 'python: object.getPortalType() == "Foo"'
# XXX condition is a TALES Expression; is it part of the API ? # Additional Constraint parameters are configured here.
# how to use condition based on a workflow state in a workflow before # Constraint docstring should provide a configuration example and a
# script, where the document is not in that state yet ? # documentation on parameter they accept.
'condition': 'python: object.getPortalType() == "Foo"' }
)
# Additional Constraint parameters are configured here.
# Constraint docstring should provide a configuration example and a
# documentation on parameter they accept.
}
)
Those constraint definition parameters will be available from the Constraint Those constraint definition parameters will be available from the Constraint
instance as `self.constraint_definition` (a dict). instance as 'self.constraint_definition' (a dict).
Calling checkConsistency() method on any ERP5Type document will check all Calling checkConsistency() method on any ERP5Type document will check all
constraint defined on this document. If the document is a subclass of constraint defined on this document. If the document is a subclass of
...@@ -80,30 +83,31 @@ class Constraint(Interface): ...@@ -80,30 +83,31 @@ class Constraint(Interface):
""" """
def checkConsistency(obj, fixit=0): def checkConsistency(obj, fixit=0):
"""This method checks the consistency of object `obj`, and fix errors if """This method checks the consistency of object 'obj', and fix errors if
the argument `fixit` is true. Not all constraint have to support error the argument 'fixit' is true. Not all constraint have to support error
repairing, in that case, simply ignore the fixit parameter. repairing, in that case, simply ignore the fixit parameter.
This method should return a list of errors, which are a list for now. This method should return a list of errors, which are a list for now.
""" """
def _generateError(obj, error_message, mapping={}): def _generateError(obj, error_message, mapping={}):
"""Generate an error for `obj` with the corresponding `error_message`. """Generate an error for 'obj' with the corresponding 'error_message'.
This method is usefull for Constraint authors, in case of an error, they This method is usefull for Constraint authors, in case of an error, they
can simply call: can simply call::
>>> if something_is_wrong: >>> if something_is_wrong:
>>> errors.append(self._generateError(obj, 'Something is wrong !') >>> errors.append(self._generateError(obj, 'Something is wrong !')
Then this message ('Something is wrong !') will be translated when the Then this message ("Something is wrong !") will be translated when the
caller of document.checkConsistency() calls getTranslatedMessage() on caller of document.checkConsistency() calls getTranslatedMessage() on
ConsistencyMessage instances returned by checkConsistency. ConsistencyMessage instances returned by checkConsistency.
The implementation uses ERP5Type's Messages, so it's possible to use a The implementation uses ERP5Type's Messages, so it's possible to use a
`mapping` for substitution, like this: 'mapping' for substitution, like this::
>>> if something_is_wrong:
>>> errors.append(self._generateError(obj, >>> if something_is_wrong:
... 'Something is wrong: ${wrong_thing}', >>> errors.append(self._generateError(obj,
... mapping=dict(wrong_thing=obj.getTheWrongThing()))) ... 'Something is wrong: ${wrong_thing}',
... mapping=dict(wrong_thing=obj.getTheWrongThing())))
""" """
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment