To create a
"Custom Rule", you must create a class inherited from the Portafilter
"Rule" class.
A rule class contains two main methods:
"passes" and
"message". The
passes method receives the
attribute value,
name, and a list of
additional parameters. It must return
True or
False depending on whether the attribute value is
valid or not. The
message method should return the validation error message that should be used when validation fails:
Now, assign the custom rule to the attributes. You can create an instance of the rule with the proper additional parameters or just pass the reference of it:
The additional parameters must pass as the
arguments:
CustomRule(foo, bar, ...)