From b33b62824e4583378801506dc25d3e9e97fa8423 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Fri, 28 Jul 2017 22:48:30 +0000 Subject: [PATCH] Added a document name validator to avoid new documents with unwanted characters in the name. - Legacy-Id: 13998 --- ietf/doc/models.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ietf/doc/models.py b/ietf/doc/models.py index c6bc17e3f..8663bed00 100644 --- a/ietf/doc/models.py +++ b/ietf/doc/models.py @@ -9,8 +9,8 @@ from django.db import models from django.core import checks from django.core.cache import caches from django.core.exceptions import ValidationError +from django.core.validators import URLValidator, RegexValidator from django.urls import reverse as urlreverse -from django.core.validators import URLValidator from django.contrib.contenttypes.models import ContentType from django.conf import settings from django.utils.html import mark_safe @@ -542,8 +542,15 @@ class DocumentAuthor(DocumentAuthorInfo): def __unicode__(self): return u"%s %s (%s)" % (self.document.name, self.person, self.order) + +validate_docname = RegexValidator( + r'^[-a-z0-9]+$', + "Provide a valid document name consisting of lowercase letters, numbers and hyphens.", + 'invalid' +) + class Document(DocumentInfo): - name = models.CharField(max_length=255, primary_key=True) # immutable + name = models.CharField(max_length=255, primary_key=True, validators=[validate_docname,]) # immutable def __unicode__(self): return self.name