datatracker/ietf/utils/fields.py
Ole Laursen f7ac066059 Integrate Secretariat tools MultiEmailField with the one in
utils/fields.py, also fix a couple of issues in NomCom tool (spelling
bugs and avoid overwriting base_fields on forms with dynamic data)
 - Legacy-Id: 8276
2014-08-17 14:39:23 +00:00

26 lines
738 B
Python

from django import forms
from django.core.validators import validate_email
class MultiEmailField(forms.Field):
def to_python(self, value):
"Normalize data to a list of strings."
# Return an empty list if no input was given.
if not value:
return []
if isinstance(value, basestring):
values = value.split(',')
return [ x.strip() for x in values if x.strip() ]
else:
return value
def validate(self, value):
"Check if value consists only of valid emails."
# Use the parent's handling of required fields, etc.
super(MultiEmailField, self).validate(value)
for email in value:
validate_email(email)