# Path: select_multiple_field/codecs.py
# def decode_csv_to_list(encoded):
#     """
#     Decodes a delimiter separated string to a Python list
#     """
#     delimiter = getattr(
#         settings, 'SELECTMULTIPLEFIELD_DELIMITER', DEFAULT_DELIMITER)
#     if encoded == '':
#         return []
# 
#     decoded = sorted(set(encoded.split(delimiter)))
#     return decoded
# 
# def encode_list_to_csv(decoded):
#     """
#     Encodes a Python list to a delimiter separated string
# 
#     Note: This sorts the list lexicographically
#     """
#     delimiter = getattr(
#         settings, 'SELECTMULTIPLEFIELD_DELIMITER', DEFAULT_DELIMITER)
#     decoded = sorted(set(decoded))
#     return delimiter.join(decoded)
# 
# Path: select_multiple_field/validators.py
# class MaxChoicesValidator(validators.BaseValidator):
# 
#     message = ungettext_lazy(
#         'Ensure this value has at most %(limit_value)d choice (it has %(show_value)d).',  # NOQA
#         'Ensure this value has at most %(limit_value)d choices (it has %(show_value)d).',  # NOQA
#         'limit_value')
#     code = 'max_choices'
# 
#     def compare(self, a, b):
#         return a > b
# 
#     def clean(self, x):
#         return len(x)
# 
# class MaxLengthValidator(validators.BaseValidator):
# 
#     message = ungettext_lazy(
#         'Ensure this value has at most %(limit_value)d character (it has %(show_value)d).',  # NOQA
#         'Ensure this value has at most %(limit_value)d characters (it has %(show_value)d).',  # NOQA
#         'limit_value')
#     code = 'max_length'
# 
#     def compare(self, a, b):
#         return a > b
# 
#     def clean(self, value):
#         return len(force_text(encode_list_to_csv(value)))


from django.core import exceptions, validators
from django.db import models
from django.utils import six
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.text import capfirst
from django.utils.translation import ugettext_lazy as _
from .codecs import decode_csv_to_list, encode_list_to_csv
from .validators import MaxChoicesValidator, MaxLengthValidator
            from south.modelsinspector import introspector
import select_multiple_field.forms as forms

    def __str__(self):
        return "%s" % force_text(self.description)

    def get_internal_type(self):
        return "CharField"

    def to_python(self, value):
        """
        When SelectMultipleField is assigned a value, this method coerces
        into a list usable by Python

        value is Encoded strings from the database or Python native types in
        need of validation

        Raises ValidationError if value is not in choices or if invalid type

        Returns list
        """
        if value is None:
            return value

        elif isinstance(value, (list, tuple)):
            self.validate_options_list(value)
            return value

        elif isinstance(value, six.string_types):
            #
            # Strings are always encoded choices
            #

# Path: select_multiple_field/codecs.py
# def decode_csv_to_list(encoded):
#     """
#     Decodes a delimiter separated string to a Python list
#     """
#     delimiter = getattr(
#         settings, 'SELECTMULTIPLEFIELD_DELIMITER', DEFAULT_DELIMITER)
#     if encoded == '':
#         return []
# 
#     decoded = sorted(set(encoded.split(delimiter)))
#     return decoded
# 
# def encode_list_to_csv(decoded):
#     """
#     Encodes a Python list to a delimiter separated string
# 
#     Note: This sorts the list lexicographically
#     """
#     delimiter = getattr(
#         settings, 'SELECTMULTIPLEFIELD_DELIMITER', DEFAULT_DELIMITER)
#     decoded = sorted(set(decoded))
#     return delimiter.join(decoded)
# 
# Path: select_multiple_field/validators.py
# class MaxChoicesValidator(validators.BaseValidator):
# 
#     message = ungettext_lazy(
#         'Ensure this value has at most %(limit_value)d choice (it has %(show_value)d).',  # NOQA
#         'Ensure this value has at most %(limit_value)d choices (it has %(show_value)d).',  # NOQA
#         'limit_value')
#     code = 'max_choices'
# 
#     def compare(self, a, b):
#         return a > b
# 
#     def clean(self, x):
#         return len(x)
# 
# class MaxLengthValidator(validators.BaseValidator):
# 
#     message = ungettext_lazy(
#         'Ensure this value has at most %(limit_value)d character (it has %(show_value)d).',  # NOQA
#         'Ensure this value has at most %(limit_value)d characters (it has %(show_value)d).',  # NOQA
#         'limit_value')
#     code = 'max_length'
# 
#     def compare(self, a, b):
#         return a > b
# 
#     def clean(self, value):
#         return len(force_text(encode_list_to_csv(value)))


# Path: select_multiple_field/models.py
from django.core import exceptions, validators
from django.db import models
from django.utils import six
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.text import capfirst
from django.utils.translation import ugettext_lazy as _
from .codecs import decode_csv_to_list, encode_list_to_csv
from .validators import MaxChoicesValidator, MaxLengthValidator
            from south.modelsinspector import introspector
import select_multiple_field.forms as forms


    def __str__(self):
        return "%s" % force_text(self.description)

    def get_internal_type(self):
        return "CharField"

    def to_python(self, value):
        """
        When SelectMultipleField is assigned a value, this method coerces
        into a list usable by Python

        value is Encoded strings from the database or Python native types in
        need of validation

        Raises ValidationError if value is not in choices or if invalid type

        Returns list
        """
        if value is None:
            return value

        elif isinstance(value, (list, tuple)):
            self.validate_options_list(value)
            return value

        elif isinstance(value, six.string_types):
            #
            # Strings are always encoded choices
            #

            native = decode_csv_to_list(value)