Added a validator to Document.title to prevent control chars in the title (complementing a recent cleanup of more than 120 instances of document titles containing vertical tabs)
- Legacy-Id: 12893
This commit is contained in:
parent
858d855eff
commit
c889856dfa
|
@ -18,7 +18,7 @@ from ietf.name.models import ( DocTypeName, DocTagName, StreamName, IntendedStdL
|
|||
DocRelationshipName, DocReminderTypeName, BallotPositionName, ReviewRequestStateName )
|
||||
from ietf.person.models import Email, Person
|
||||
from ietf.utils.admin import admin_link
|
||||
|
||||
from ietf.utils.validators import validate_no_control_chars
|
||||
|
||||
class StateType(models.Model):
|
||||
slug = models.CharField(primary_key=True, max_length=30) # draft, draft-iesg, charter, ...
|
||||
|
@ -65,7 +65,7 @@ class DocumentInfo(models.Model):
|
|||
time = models.DateTimeField(default=datetime.datetime.now) # should probably have auto_now=True
|
||||
|
||||
type = models.ForeignKey(DocTypeName, blank=True, null=True) # Draft, Agenda, Minutes, Charter, Discuss, Guideline, Email, Review, Issue, Wiki, External ...
|
||||
title = models.CharField(max_length=255)
|
||||
title = models.CharField(max_length=255, validators=[validate_no_control_chars, ])
|
||||
|
||||
states = models.ManyToManyField(State, blank=True) # plain state (Active/Expired/...), IESG state, stream state
|
||||
tags = models.ManyToManyField(DocTagName, blank=True) # Revised ID Needed, ExternalParty, AD Followup, ...
|
||||
|
|
|
@ -5,10 +5,19 @@ from __future__ import unicode_literals
|
|||
import re
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import RegexValidator
|
||||
from django.utils.deconstruct import deconstructible
|
||||
|
||||
# Note that this is an instantiation of the regex validator, _not_ the
|
||||
# regex-string validator defined right below
|
||||
validate_no_control_chars = RegexValidator(
|
||||
regex="^[^\x00-\x1f]*$",
|
||||
message="Please enter a string without control characters." )
|
||||
|
||||
|
||||
@deconstructible
|
||||
class RegexStringValidator(object):
|
||||
"Validates that a given regular expression can be compiled."
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
@ -36,3 +45,4 @@ class RegexStringValidator(object):
|
|||
return not (self == other)
|
||||
|
||||
validate_regular_expression_string = RegexStringValidator()
|
||||
|
||||
|
|
Loading…
Reference in a new issue