from django.core.exceptions import ImproperlyConfigured
from django.db.models.fields import CharField
from django.utils.translation import ugettext_lazy

import six

from django_markup.markup import formatter


class MarkupField(CharField):
    '''
    A CharField that holds the markup name for the row. In the admin it's
    displayed as a ChoiceField.
    '''

    def __init__(self, default=False, formatter=formatter, *args, **kwargs):
        # Check that the default value is a valid filter
        if default:
            if default not in formatter.filter_list:
                raise ImproperlyConfigured(
                    "'%s' is not a registered markup filter. Registered filters are: %s."
                    % (default, ', '.join(six.iterkeys(formatter.filter_list)))
                )
            kwargs.setdefault('default', default)

        kwargs.setdefault('max_length', 255)
        kwargs.setdefault('choices', formatter.choices())
        kwargs.setdefault('verbose_name', ugettext_lazy('markup'))
        CharField.__init__(self, *args, **kwargs)


# Tell South how to freeze the MarkupField model.
# Because MarkupField inherits from CharField and does not add any new
# arguments, no special introspection rules are needed.
try:
    from south.modelsinspector import add_introspection_rules

    add_introspection_rules([], ['django_markup\.fields\.MarkupField'])
except ImportError:
    pass

@@ -238,19 +238,19 @@
 d):%0A    
-'''
+%22%22%22
 %0A    A C
@@ -356,11 +356,11 @@
     
-'''
+%22%22%22
 %0A%0A  
@@ -1072,351 +1072,4 @@
 s)%0A%0A
-%0A# Tell South how to freeze the MarkupField model.%0A# Because MarkupField inherits from CharField and does not add any new%0A# arguments, no special introspection rules are needed.%0Atry:%0A    from south.modelsinspector import add_introspection_rules%0A%0A    add_introspection_rules(%5B%5D, %5B'django_markup%5C.fields%5C.MarkupField'%5D)%0Aexcept ImportError:%0A    pass%0A

Remove South support