# Path: mutant/db/fields/python.py
# class DirectoryPathField(CharField):
#     def validate(self, value, model_instance):
#         if not os.path.exists(value):
#             raise ValidationError(_("Specified path doesn't exist"))
#         elif not os.path.isdir(value):
#             raise ValidationError(_("Specified path isn't a directory"))
# 
# class RegExpStringField(CharField):
#     def to_python(self, value):
#         value = super(RegExpStringField, self).to_python(value)
#         if value is None:
#             return
#         try:
#             re.compile(value)
#         except Exception as e:
#             raise ValidationError(_(e))
#         else:
#             return value
# 
# Path: mutant/models/field/managers.py
# class FieldDefinitionManager(PolymorphicManager.from_queryset(FieldDefinitionQuerySet)):
#     def get_by_natural_key(self, app_label, model, name):
#         qs = self.select_subclasses()
#         return qs.get(model_def__app_label=app_label,
#                       model_def__model=model, name=name)
# 
#     def names(self):
#         qs = self.get_queryset()
#         return qs.order_by('name').values_list('name', flat=True)
# 
#     def create_with_default(self, default, **kwargs):
#         qs = self.get_queryset()
#         return qs.create_with_default(default, **kwargs)
# 
# Path: mutant/contrib/text/models.py
# class CharFieldDefinition(FieldDefinition):
#     max_length = fields.PositiveSmallIntegerField(
#         _('max length'), blank=True, null=True
#     )
# 
#     objects = FieldDefinitionManager()
# 
#     class Meta:
#         app_label = 'text'
#         defined_field_class = fields.CharField
#         defined_field_options = ('max_length',)
#         defined_field_description = _('String')
#         defined_field_category = _('Text')


from django.db.models import fields
from django.utils.translation import ugettext_lazy as _
from ...db.fields.python import DirectoryPathField, RegExpStringField
from ...models.field.managers import FieldDefinitionManager
from ..text.models import CharFieldDefinition
from __future__ import unicode_literals



path_help_text = _('The absolute filesystem path to a directory from which '
                   'this field should get its choices.')
match_help_text = _('A regular expression used to filter filenames.')
recursive_help_text = _('Specifies whether all subdirectories of '
                        'path should be included')


class FilePathFieldDefinition(CharFieldDefinition):
    path = DirectoryPathField(_('path'), max_length=100,

# Path: mutant/db/fields/python.py
# class DirectoryPathField(CharField):
#     def validate(self, value, model_instance):
#         if not os.path.exists(value):
#             raise ValidationError(_("Specified path doesn't exist"))
#         elif not os.path.isdir(value):
#             raise ValidationError(_("Specified path isn't a directory"))
# 
# class RegExpStringField(CharField):
#     def to_python(self, value):
#         value = super(RegExpStringField, self).to_python(value)
#         if value is None:
#             return
#         try:
#             re.compile(value)
#         except Exception as e:
#             raise ValidationError(_(e))
#         else:
#             return value
# 
# Path: mutant/models/field/managers.py
# class FieldDefinitionManager(PolymorphicManager.from_queryset(FieldDefinitionQuerySet)):
#     def get_by_natural_key(self, app_label, model, name):
#         qs = self.select_subclasses()
#         return qs.get(model_def__app_label=app_label,
#                       model_def__model=model, name=name)
# 
#     def names(self):
#         qs = self.get_queryset()
#         return qs.order_by('name').values_list('name', flat=True)
# 
#     def create_with_default(self, default, **kwargs):
#         qs = self.get_queryset()
#         return qs.create_with_default(default, **kwargs)
# 
# Path: mutant/contrib/text/models.py
# class CharFieldDefinition(FieldDefinition):
#     max_length = fields.PositiveSmallIntegerField(
#         _('max length'), blank=True, null=True
#     )
# 
#     objects = FieldDefinitionManager()
# 
#     class Meta:
#         app_label = 'text'
#         defined_field_class = fields.CharField
#         defined_field_options = ('max_length',)
#         defined_field_description = _('String')
#         defined_field_category = _('Text')


# Path: mutant/contrib/file/models.py
from django.db.models import fields
from django.utils.translation import ugettext_lazy as _
from ...db.fields.python import DirectoryPathField, RegExpStringField
from ...models.field.managers import FieldDefinitionManager
from ..text.models import CharFieldDefinition

from __future__ import unicode_literals



path_help_text = _('The absolute filesystem path to a directory from which '
                   'this field should get its choices.')
match_help_text = _('A regular expression used to filter filenames.')
recursive_help_text = _('Specifies whether all subdirectories of '
                        'path should be included')


class FilePathFieldDefinition(CharFieldDefinition):
    path = DirectoryPathField(_('path'), max_length=100,

                              help_text=path_help_text)