# Path: shared_schema_tenants/exceptions.py
# class TenantFieldTypeConfigurationError(Exception):
# 
#     def __init__(self, message="The field is not configured correctly", errors=[]):
#         super(TenantFieldTypeConfigurationError, self).__init__(message)
# 
# Path: shared_schema_tenants/helpers/tenants.py
# def get_current_tenant():
#     from shared_schema_tenants.middleware import TenantMiddleware
#     return TenantMiddleware.get_current_tenant()


import sys
from django.core.exceptions import ValidationError
from django.utils.text import ugettext_lazy as _
from shared_schema_tenants.exceptions import TenantFieldTypeConfigurationError
from shared_schema_tenants.helpers.tenants import get_current_tenant

    def get_tenant_default_fields_values(self):
        return getattr(self, 'tenant_default_fields_values', {})

    def get_tenant(self):
        return self.instance

    def get_field(self, instance, field_key):
        fields = getattr(instance, self.instance_field_name)
        if fields:
            return fields.get(field_key, None)

        return None

    def validate_field(self, context, key, value, original_value=None):
        tenant_fields = self.get_tenant_fields()

        try:
            field = tenant_fields[key]
        except KeyError:
            raise ValidationError(_('%(field)s is not a valid field') % {'field': key})

        try:
            field_type = field['type']
        except KeyError:
            raise TenantFieldTypeConfigurationError((
                'You must define a valid type for tenant setting '
                'field "%(field)s" in "TENANT_SETTINGS_FIELDS"') % {'field': key})

        if field_type not in self.TYPES_TO_INTERNAL_MAP.keys():

# Path: shared_schema_tenants/exceptions.py
# class TenantFieldTypeConfigurationError(Exception):
# 
#     def __init__(self, message="The field is not configured correctly", errors=[]):
#         super(TenantFieldTypeConfigurationError, self).__init__(message)
# 
# Path: shared_schema_tenants/helpers/tenants.py
# def get_current_tenant():
#     from shared_schema_tenants.middleware import TenantMiddleware
#     return TenantMiddleware.get_current_tenant()


# Path: shared_schema_tenants/helpers/tenant_json_field.py
import sys
from django.core.exceptions import ValidationError
from django.utils.text import ugettext_lazy as _
from shared_schema_tenants.exceptions import TenantFieldTypeConfigurationError
from shared_schema_tenants.helpers.tenants import get_current_tenant


    def get_tenant_default_fields_values(self):
        return getattr(self, 'tenant_default_fields_values', {})

    def get_tenant(self):
        return self.instance

    def get_field(self, instance, field_key):
        fields = getattr(instance, self.instance_field_name)
        if fields:
            return fields.get(field_key, None)

        return None

    def validate_field(self, context, key, value, original_value=None):
        tenant_fields = self.get_tenant_fields()

        try:
            field = tenant_fields[key]
        except KeyError:
            raise ValidationError(_('%(field)s is not a valid field') % {'field': key})

        try:
            field_type = field['type']
        except KeyError:
            raise TenantFieldTypeConfigurationError((
                'You must define a valid type for tenant setting '
                'field "%(field)s" in "TENANT_SETTINGS_FIELDS"') % {'field': key})

        if field_type not in self.TYPES_TO_INTERNAL_MAP.keys():

            raise TenantFieldTypeConfigurationError((