#22959: Document that custom validator must be comparable to prevent infinite
migrations
--------------------------------------+------------------------------------
Reporter: lorinkoz@… | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: migrations | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by lorinkoz):
Here's the original validator I used to get to know the problem (of
course, by the time I discovered it there was no __cmp__)
{{{
class LimitWordsValidator:
def __init__(self, limit, upper=True):
self.limit = limit
self.upper = upper
def __cmp__(x, y):
return cmp(x.limit, y.limit) or cmp(x.upper, y.upper)
def __call__(self, value):
words = len(strip_tags(value).split())
args = {
'limit': self.limit,
'current': words,
}
if self.upper and words > self.limit:
raise ValidationError(_('You cannot exceed %(limit)s words,
you have %(current)s.') % args)
if not self.upper and words < self.limit:
raise ValidationError(_('You need at least %(limit)s words,
you have %(current)s.') % args)
def deconstruct(self):
return (
'common.validators.LimitWordsValidator',
[self.limit],
{'upper': self.upper},
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22959#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/076.a877a459db16c2a05f894fe29fda3214%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.