From d2f0ff7f3701f5c410cf4a7f6cdf5af1124fc42f Mon Sep 17 00:00:00 2001 From: Christophe Boulanger Date: Mon, 8 May 2017 15:19:57 +0200 Subject: [PATCH] Comma is not allowed in motivations title --- passerelle_imio_ts1_datasources/models.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/passerelle_imio_ts1_datasources/models.py b/passerelle_imio_ts1_datasources/models.py index 45dfb55..268113b 100644 --- a/passerelle_imio_ts1_datasources/models.py +++ b/passerelle_imio_ts1_datasources/models.py @@ -17,6 +17,7 @@ import decimal from django.db import models +from django.core.validators import RegexValidator from django.utils.translation import ugettext_lazy as _ from passerelle.base.models import BaseResource @@ -24,7 +25,12 @@ from passerelle.utils.api import endpoint class MotivationTerm(models.Model): - text = models.CharField(max_length=100) + no_comma_validator = [ + RegexValidator(regex=r'^((?!,).)*$', + message=_("Comma is not allowed in motivations title (NO \",\")."), + code='invalid_text') + ] + text = models.CharField(max_length=100, validators=no_comma_validator) slug = models.CharField(max_length=100) price = models.DecimalField(decimal_places=2, max_digits=6) description = models.TextField(max_length=500)