Added a validator for the reviewer settings' Filter Regexp field, to make sure that we don't later hit exceptions when trying to compile and use the regexp entered.
- Legacy-Id: 12439
This commit is contained in:
parent
e3ce2a9657
commit
5959b3a46a
|
@ -6,6 +6,7 @@ from ietf.doc.models import Document
|
|||
from ietf.group.models import Group
|
||||
from ietf.person.models import Person, Email
|
||||
from ietf.name.models import ReviewTypeName, ReviewRequestStateName, ReviewResultName
|
||||
from ietf.utils.validators import validate_regular_expression_string
|
||||
|
||||
class ReviewerSettings(models.Model):
|
||||
"""Keeps track of admin data associated with a reviewer in a team."""
|
||||
|
@ -19,7 +20,9 @@ class ReviewerSettings(models.Model):
|
|||
(91, "Once per quarter"),
|
||||
]
|
||||
min_interval = models.IntegerField(verbose_name="Can review at most", choices=INTERVALS, blank=True, null=True)
|
||||
filter_re = models.CharField(max_length=255, verbose_name="Filter regexp", blank=True, help_text="Draft names matching regular expression should not be assigned")
|
||||
filter_re = models.CharField(max_length=255, verbose_name="Filter regexp", blank=True,
|
||||
validators=[validate_regular_expression_string, ],
|
||||
help_text="Draft names matching this regular expression should not be assigned")
|
||||
skip_next = models.IntegerField(default=0, verbose_name="Skip next assignments")
|
||||
remind_days_before_deadline = models.IntegerField(null=True, blank=True, help_text="To get an email reminder in case you forget to do an assigned review, enter the number of days before review deadline you want to receive it. Clear the field if you don't want a reminder.")
|
||||
|
||||
|
|
32
ietf/utils/validators.py
Normal file
32
ietf/utils/validators.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# -*- python -*-
|
||||
# Copyright The IETF Trust 2007, All Rights Reserved
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
|
||||
class RegexStringValidator(object):
|
||||
|
||||
def __init__(self,):
|
||||
pass
|
||||
|
||||
def __call__(self, value):
|
||||
"""
|
||||
Validates that the given regular expression can be compiled.
|
||||
"""
|
||||
try:
|
||||
re.compile(value)
|
||||
except Exception as e:
|
||||
raise ValidationError('Please enter a valid regular expression. '
|
||||
'Got an error when trying to compile this: "%s" : "%s"'
|
||||
% (self.message, value, e))
|
||||
if '-*' in value:
|
||||
raise ValidationError('Did you really mean that? The regular expression '
|
||||
'contains "-*" which will match zero or more dashes. '
|
||||
'Maybe you meant to write "-.*"? If you actually meant "-*", '
|
||||
'you can use "[-]*" instead to get past this error.')
|
||||
|
||||
|
||||
validate_regular_expression_string = RegexStringValidator()
|
Loading…
Reference in a new issue