Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regex field in guillotina schema #1096

Open
rboixaderg opened this issue Jan 29, 2021 · 1 comment
Open

Add regex field in guillotina schema #1096

rboixaderg opened this issue Jan 29, 2021 · 1 comment
Labels
GIP Guillotina Improvement Proposal
Milestone

Comments

@rboixaderg
Copy link
Contributor

Add regex field in guillotina schema

@rboixaderg rboixaderg added the GIP Guillotina Improvement Proposal label Jan 29, 2021
@rboixaderg rboixaderg added this to the G7 milestone Jan 29, 2021
@masipcat
Copy link
Contributor

You can use this in the meantime:

@implementer(ITextLine)
class RegexField(schema.TextLine):
    def __init__(self, *args, regex, **kwargs):
        super().__init__(*args, **kwargs)
        self.regex = re.compile(regex)

    def _validate(self, value):
        super()._validate(value)
        if not self.regex.match(value):
            raise InvalidValue(value, self.__name__)
rgba_color = RegexField(regex=r"^#[0-9A-Fa-f]{6,8}$")

I can open a PR as well if we want this in Guillotina.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GIP Guillotina Improvement Proposal
Projects
None yet
Development

No branches or pull requests

2 participants