[Cubicweb] RQLConstraint attributes validation

Carlos Balderas carlos.balderas at gmail.com
Tue May 13 23:22:50 CEST 2014


Hi Aurélien,

Thank you very much for your quick answer.

I think I will take hooks as solution for now ;), but debugging should be a
good thing to do in order to understand better the constraints.

I appreciate very much your help.

Best Regards!
Carlos Balderas

On Tue, May 13, 2014 at 10:37 AM, Aurélien Campéas <
aurelien.campeas at logilab.fr> wrote:

> On 13/05/2014 01:31, Carlos Balderas wrote:
> > Hello List,
>
> Hello Carlos,
>
> >
> > 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'))])
>
> Also given how you have:
>
> * to defend against unset attributes
> * 4 attributes
>
> maybe it would be easier to implement with a hook on entity
> creation/update (code-complexity-wise) ...
>
> >
> >
> > 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.
>
> You will probably want to debug this with DBG_OPS, and putting prints
> in RepoEnforcedRQLConstraintMixIn.exec_query maybe (in cw/schema.py).
>
> Also proofreading surely helps :)
> Note, e.g. the following:
>
> RQLConstraint('(S start NULL)'
>               ' OR (S start <= B, S finished B)'
>               ' OR (S finished NULL)')
>
> Maybe you need:
>
>  ((S start NULL) OR (S finished NULL)) OR (S start <= B, S finished B)
>
> (or something).
>
> Regards,
> Aurélien.
> _______________________________________________
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
> http://lists.cubicweb.org/mailman/listinfo/cubicweb
>



-- 
Carlos Balderas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20140513/6f96e6bb/attachment-0102.html>


More information about the Cubicweb mailing list