diff --git a/multi_email_field/forms.py b/multi_email_field/forms.py index d85ca69..df913c6 100644 --- a/multi_email_field/forms.py +++ b/multi_email_field/forms.py @@ -16,7 +16,10 @@ def to_python(self, value): # Return None if no input was given. if not value: return [] - return [v.strip() for v in value.splitlines() if v != ""] + if isinstance(value, list): + return [v.strip() for v in value if v != ""] + else: + return [v.strip() for v in value.splitlines() if v != ""] def validate(self, value): """ Check if value consists only of valid emails. """ diff --git a/multi_email_field/tests/tests.py b/multi_email_field/tests/tests.py index e44bf24..cd62911 100644 --- a/multi_email_field/tests/tests.py +++ b/multi_email_field/tests/tests.py @@ -116,6 +116,10 @@ def test__to_python(self): val = 'foo@bar.com\nfoo2@bar2.com\r\nfoo3@bar3.com' self.assertEquals(['foo@bar.com', 'foo2@bar2.com', 'foo3@bar3.com'], f.to_python(val)) + # Multi elements list values + val = ['foo4@bar4.com', 'foo5@bar5.com', 'foo6@bar6.com'] + self.assertEquals(['foo4@bar4.com', 'foo5@bar5.com', 'foo6@bar6.com'], + f.to_python(val)) def test__validate(self): f = MultiEmailFormField(required=True) diff --git a/setup.py b/setup.py index 230f096..84b6bcc 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ description="Provides a model field and a form field to manage list of e-mails", long_description=open(os.path.join(here, 'README.rst')).read() + '\n\n' + open(os.path.join(here, 'CHANGES')).read(), - license='LGPL, see LICENSE file.', + license='LGPL', install_requires=['Django'], packages=find_packages(), include_package_data=True,