[Cubicweb] FW: [cubicweb] Constraint an Entity's attribute of type String to a regular expression?

christine.absil at engie.com christine.absil at engie.com
Thu Sep 10 16:06:55 CEST 2020


Thank you very much, Noé ! 😊

From: Cubicweb <cubicweb-bounces at lists.cubicweb.org> On Behalf Of Noé Gaumont
Sent: jeudi 10 septembre 2020 14:48
To:
Subject: Re: [Cubicweb] [cubicweb] Constraint an Entity's attribute of type String to a regular expression?


Hi,

It is possible to declare constraints on attributes.
The documentation is available https://cubicweb.readthedocs.io/en/3.28/book/devrepo/datamodel/definition/#constraints<https://urldefense.com/v3/__https:/cubicweb.readthedocs.io/en/3.28/book/devrepo/datamodel/definition/*constraints__;Iw!!La4veWw!jYENBOp984p7Gfomt5PRh8wa1EhVg1iv80W7UhUwNcS9DhoJbudyWn_NqfMRDCb3PA8$> , but do not list RegExp.

For regexp constraints, see https://yams.readthedocs.io/en/latest/yams.html#yams.constraints.RegexpConstraint<https://urldefense.com/v3/__https:/yams.readthedocs.io/en/latest/yams.html*yams.constraints.RegexpConstraint__;Iw!!La4veWw!jYENBOp984p7Gfomt5PRh8wa1EhVg1iv80W7UhUwNcS9DhoJbudyWn_NqfMRO_jX08Y$>

For your use-case, it would be :

from yams.constraints import RegexpConstraint



class Organisation(EntityType):

         name = String(required=True, unique=True, maxsize=255, constraints=[RegexpConstraint('^[^_]*$')])

Noé
Le 10/09/2020 à 14:31, christine.absil at engie.com<mailto:christine.absil at engie.com> a écrit :
Hi all,

A simple (and stupid?) question : in a cubicweb schema, is it (“natively”) possible to constrain an Entity string attribute to a regular expression?
Would there be a dedicated param of the String function to declare that?

For instance, if I wanted my Organisations names not to contain any “_” character

class Organisation(EntityType):
    name = String(required=True, unique=True, maxsize=255)

Many thanks

Regards

Christine
ENGIE Mail Disclaimer: http://www.engie.com/disclaimer/



_______________________________________________

Cubicweb mailing list

Cubicweb at lists.cubicweb.org<mailto:Cubicweb at lists.cubicweb.org>

https://lists.cubicweb.org/mailman/listinfo/cubicweb<https://urldefense.com/v3/__https:/lists.cubicweb.org/mailman/listinfo/cubicweb__;!!La4veWw!jYENBOp984p7Gfomt5PRh8wa1EhVg1iv80W7UhUwNcS9DhoJbudyWn_NqfMRVUJNOLM$>

ENGIE Mail Disclaimer: http://www.engie.com/disclaimer/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20200910/d26e86c4/attachment-0027.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ATT00001.txt
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20200910/d26e86c4/attachment-0027.txt>


More information about the Cubicweb mailing list