2016-02-09 21:04:29 +01:00
|
|
|
from ..utils.rest_api import ValidationError
|
|
|
|
|
|
|
|
|
|
|
|
def default_votes_validator(data):
|
|
|
|
"""
|
|
|
|
Use this validator in your poll serializer. It checks that the values
|
|
|
|
for the default votes (see models.CollectDefaultVotesMixin) are greater
|
|
|
|
than or equal to -2.
|
|
|
|
"""
|
|
|
|
for key in data:
|
2019-01-06 16:22:33 +01:00
|
|
|
if (
|
|
|
|
key in ("votesvalid", "votesinvalid", "votescast")
|
|
|
|
and data[key] is not None
|
|
|
|
and data[key] < -2
|
|
|
|
):
|
|
|
|
raise ValidationError(
|
2019-09-02 11:09:03 +02:00
|
|
|
{"detail": "Value for {0} must not be less than -2", "args": [key]}
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
2016-02-09 21:04:29 +01:00
|
|
|
return data
|