[Cubicweb] RQLConstraint attributes validation

Carlos Balderas carlos.balderas at gmail.com
Tue May 13 01:31:09 CEST 2014


Hello List,

I am failing to make a validation using RQLConstraint. What I am trying to
accomplish is to validate dates among attributes of the same entity, making
the following validations:

 (finished date >= prevision date) & (prevision date >= start date)

none of the dates are required, but if you need to set prevision date then
you must set start date, same thing for finished date.

Here is the entity:

class ProjectStage(WorkflowableEntityType):
    """a project stage groups a list of activities/todo's to be completed
    in certain amount of time.
    """
    start = Datetime(description=_('start date'),
                 constraints=[
            RQLConstraint('(S start NULL)'
                          ' OR (S start <= B, S prevision B)'
                          ' OR (S prevision NULL)',
                          msg=_('start date should be'
                                ' less than or equal to'
                                ' prevision date')),
            RQLConstraint('(S start NULL)'
                          ' OR (S start <= B, S finished B)'
                          ' OR (S finished NULL)',
                          msg=_('start date should be'
                                ' less than or equal to'
                                ' finish date'))])
    prevision = Datetime(description=_('estimated finish date'),
                     constraints=[
            RQLConstraint('(S prevision NULL)'
                          ' OR (S prevision >= B, S start B)'
                          ' OR (S start NULL)',
                          msg=_('prevision date should be'
                                ' greater than or equal to'
                                ' start date'))])
    finished = Datetime(description=_('real finish date'),
                        constraints=[
            RQLConstraint('(S finished NULL)'
                          ' OR (S finished >= B, S start B)'
                          ' OR (S start NULL)',
                          msg=_('finish date should be'
                                ' greater than or equal to'
                                ' start date'))])


At the time I am creating the ProjectStage entity I am getting the message
of constraint violation even though the date values are correct according
to the explained logic.

I understand this functionality can be covered by using hooks, but I really
like to know if what I am trying to do is possible by using RQLConstraints
or to find out what I am doing wrong.

I will appreciate very much your help or guidance.

Thank you very much to all!.
-- 
Carlos Balderas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20140512/9b42d5e3/attachment-0094.html>


More information about the Cubicweb mailing list