Skip to content

Commit b33b628

Browse files
committed
Added a document name validator to avoid new documents with unwanted characters in the name.
- Legacy-Id: 13998
1 parent 6eda346 commit b33b628

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

ietf/doc/models.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from django.core import checks
1010
from django.core.cache import caches
1111
from django.core.exceptions import ValidationError
12+
from django.core.validators import URLValidator, RegexValidator
1213
from django.urls import reverse as urlreverse
13-
from django.core.validators import URLValidator
1414
from django.contrib.contenttypes.models import ContentType
1515
from django.conf import settings
1616
from django.utils.html import mark_safe
@@ -542,8 +542,15 @@ class DocumentAuthor(DocumentAuthorInfo):
542542
def __unicode__(self):
543543
return u"%s %s (%s)" % (self.document.name, self.person, self.order)
544544

545+
546+
validate_docname = RegexValidator(
547+
r'^[-a-z0-9]+$',
548+
"Provide a valid document name consisting of lowercase letters, numbers and hyphens.",
549+
'invalid'
550+
)
551+
545552
class Document(DocumentInfo):
546-
name = models.CharField(max_length=255, primary_key=True) # immutable
553+
name = models.CharField(max_length=255, primary_key=True, validators=[validate_docname,]) # immutable
547554

548555
def __unicode__(self):
549556
return self.name

0 commit comments

Comments
 (0)