move MSFList class to global scope
Fixes #65 which enables serialisation with pickle
This commit is contained in:
parent
e81ad8106d
commit
3173384d68
|
@ -34,7 +34,6 @@ else:
|
||||||
|
|
||||||
# Code from six egg https://bitbucket.org/gutworth/six/src/a3641cb211cc360848f1e2dd92e9ae6cd1de55dd/six.py?at=default
|
# Code from six egg https://bitbucket.org/gutworth/six/src/a3641cb211cc360848f1e2dd92e9ae6cd1de55dd/six.py?at=default
|
||||||
|
|
||||||
|
|
||||||
def add_metaclass(metaclass):
|
def add_metaclass(metaclass):
|
||||||
"""Class decorator for creating a class with a metaclass."""
|
"""Class decorator for creating a class with a metaclass."""
|
||||||
def wrapper(cls):
|
def wrapper(cls):
|
||||||
|
@ -47,6 +46,13 @@ def add_metaclass(metaclass):
|
||||||
return wrapper
|
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):
|
class MultiSelectField(models.CharField):
|
||||||
""" Choice values can not contain commas. """
|
""" Choice values can not contain commas. """
|
||||||
|
|
||||||
|
@ -131,12 +137,6 @@ class MultiSelectField(models.CharField):
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
choices = dict(self.flatchoices)
|
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:
|
if value:
|
||||||
return value if isinstance(value, list) else MSFList(value.split(','))
|
return value if isinstance(value, list) else MSFList(value.split(','))
|
||||||
return MSFList([])
|
return MSFList([])
|
||||||
|
|
Loading…
Reference in a new issue