move MSFList class to global scope

Fixes #65 which enables serialisation with pickle
This commit is contained in:
Andrew Miller 2017-07-25 16:45:19 +01:00
parent e81ad8106d
commit 3173384d68

View file

@ -34,7 +34,6 @@ else:
# Code from six egg https://bitbucket.org/gutworth/six/src/a3641cb211cc360848f1e2dd92e9ae6cd1de55dd/six.py?at=default
def add_metaclass(metaclass):
"""Class decorator for creating a class with a metaclass."""
def wrapper(cls):
@ -47,6 +46,13 @@ def add_metaclass(metaclass):
return wrapper
@python_2_unicode_compatible
class MSFList(list):
def __str__(msgl):
l = [choices.get(int(i)) if i.isdigit() else choices.get(i) for i in msgl]
return u', '.join([string_type(s) for s in l])
class MultiSelectField(models.CharField):
""" Choice values can not contain commas. """
@ -131,12 +137,6 @@ class MultiSelectField(models.CharField):
def to_python(self, value):
choices = dict(self.flatchoices)
@python_2_unicode_compatible
class MSFList(list):
def __str__(msgl):
l = [choices.get(int(i)) if i.isdigit() else choices.get(i) for i in msgl]
return u', '.join([string_type(s) for s in l])
if value:
return value if isinstance(value, list) else MSFList(value.split(','))
return MSFList([])