From d9e23773aca210033bb4075ccbcdf2c54e25bac7 Mon Sep 17 00:00:00 2001
From: Antti Rasinen <ars@iki.fi>
Date: Fri, 23 Jan 2009 22:33:17 +0200
Subject: [PATCH] Added reject-kwarg
---
django/forms/fields.py | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/django/forms/fields.py b/django/forms/fields.py
index ccb54d8..e157ac0 100644
a
|
b
|
class DateTimeField(Field):
|
390 | 390 | raise ValidationError(self.error_messages['invalid']) |
391 | 391 | |
392 | 392 | class RegexField(CharField): |
393 | | def __init__(self, regex, max_length=None, min_length=None, error_message=None, *args, **kwargs): |
| 393 | default_error_messages = { |
| 394 | 'reject': _(u'Enter a valid value'), |
| 395 | } |
| 396 | |
| 397 | def __init__(self, regex, reject=None, max_length=None, min_length=None, error_message=None, *args, **kwargs): |
394 | 398 | """ |
395 | 399 | regex can be either a string or a compiled regular expression object. |
396 | 400 | error_message is an optional error message to use, if |
… |
… |
class RegexField(CharField):
|
404 | 408 | super(RegexField, self).__init__(max_length, min_length, *args, **kwargs) |
405 | 409 | if isinstance(regex, basestring): |
406 | 410 | regex = re.compile(regex) |
407 | | self.regex = regex |
| 411 | if reject and isinstance(reject, basestring): |
| 412 | reject = re.compile(reject) |
| 413 | self.regex, self.reject = regex, reject |
408 | 414 | |
409 | 415 | def clean(self, value): |
410 | 416 | """ |
… |
… |
class RegexField(CharField):
|
416 | 422 | return value |
417 | 423 | if not self.regex.search(value): |
418 | 424 | raise ValidationError(self.error_messages['invalid']) |
| 425 | if self.reject and self.reject.search(value): |
| 426 | raise ValidationError(self.error_messages['rejected']) |
419 | 427 | return value |
420 | 428 | |
421 | 429 | email_re = re.compile( |