示例#1
0
 def add_subfield_base_metaclass(self, cls):
     return six.add_metaclass(models.SubfieldBase)(cls)
示例#2
0
        if LTE_DJANGO_1_7:
            # could be that value is already marked safe
            # this is ok because mark_safe is idempotent
            value = mark_safe(value)
        return value

    def formfield(self, **kwargs):
        if self.configuration:
            widget = TextEditorWidget(configuration=self.configuration)
        else:
            widget = TextEditorWidget

        defaults = {
            'form_class': HTMLFormField,
            'widget': widget,
        }
        defaults.update(kwargs)

        # override the admin widget
        if defaults['widget'] == admin_widgets.AdminTextareaWidget:
            defaults['widget'] = widget
        return super(HTMLField, self).formfield(**defaults)

    def clean(self, value, model_instance):
        value = super(HTMLField, self).clean(value, model_instance)
        return clean_html(value, full=False)


if LTE_DJANGO_1_7:
    HTMLField = add_metaclass(models.SubfieldBase)(HTMLField)
示例#3
0
文件: fields.py 项目: sxxs001/cmdb
    def get_prep_lookup(self, lookup_type, value):
        # data is stored internally as integer so searching as string
        # yeild 0 result. for example: useful for search in admin.
        if lookup_type in ('exact', 'iexact', 'icontains', 'icontains'):
            try:
                return self.get_prep_value(value)
            except AddrFormatError:
                return None
        elif lookup_type in ('in'):
            try:
                macs = []
                for mac in value:
                    macs += [self.get_prep_value(mac)]
                return macs
            except AddrFormatError:
                return None
        else:
            raise TypeError('Lookup type %r not supported.' % lookup_type)


if django.VERSION < (1, 8):
    from django.utils.six import add_metaclass
    MACAddressField = add_metaclass(models.SubfieldBase)(MACAddressField)

try:
    from south.modelsinspector import add_introspection_rules
    add_introspection_rules([], ["^macaddress\.fields\.MACAddressField"])
except ImportError:
    pass
示例#4
0
def add_meta_class(field):
    if VERSION < (1, 8):
        from django.db.models import SubfieldBase
        return six.add_metaclass(SubfieldBase)(field)
    return field
示例#5
0
        if LTE_DJANGO_1_7:
            # could be that value is already marked safe
            # this is ok because mark_safe is idempotent
            value = mark_safe(value)
        return value

    def formfield(self, **kwargs):
        if self.configuration:
            widget = TextEditorWidget(configuration=self.configuration)
        else:
            widget = TextEditorWidget

        defaults = {
            'form_class': HTMLFormField,
            'widget': widget,
        }
        defaults.update(kwargs)

        # override the admin widget
        if defaults['widget'] == admin_widgets.AdminTextareaWidget:
            defaults['widget'] = widget
        return super(HTMLField, self).formfield(**defaults)

    def clean(self, value, model_instance):
        value = super(HTMLField, self).clean(value, model_instance)
        return clean_html(value, full=False)

if LTE_DJANGO_1_7:
    HTMLField = add_metaclass(models.SubfieldBase)(HTMLField)
示例#6
0
文件: compat.py 项目: essiKS/bologna
def add_meta_class(field):
    if VERSION < (1, 8):
        from django.db.models import SubfieldBase
        return six.add_metaclass(SubfieldBase)(field)
    return field
示例#7
0
        return super(MACAddressField, self).formfield(**defaults)

    def get_prep_lookup(self, lookup_type, value):
        # data is stored internally as integer so searching as string
        # yeild 0 result. for example: useful for search in admin.
        if lookup_type in ('exact', 'iexact', 'icontains', 'icontains'):
            try:
                return self.get_prep_value(value)
            except AddrFormatError:
                return None
        elif lookup_type in ('in'):
            try:
                macs = []
                for mac in value:
                    macs += [self.get_prep_value(mac)]
                return macs
            except AddrFormatError:
                return None
        else:
            raise TypeError('Lookup type %r not supported.' % lookup_type)

if django.VERSION < (1, 8):
    from django.utils.six import add_metaclass
    MACAddressField = add_metaclass(models.SubfieldBase)(MACAddressField)

try:
    from south.modelsinspector import add_introspection_rules
    add_introspection_rules([], ["^macaddress\.fields\.MACAddressField"])
except ImportError:
    pass
示例#8
0
    description = 'Domain name field'
    empty_strings_allowed = False
    default_validators = [
        domain_name_validator,
    ]

    def __init__(self, *args, **kwargs):
        kwargs['max_length'] = kwargs.get('max_length', 72)
        super(DomainNameField, self).__init__(*args, **kwargs)

    def formfield(self, **kwargs):
        defaults = {'form_class': DomainNameFormField}
        defaults.update(kwargs)
        return super(DomainNameField, self).formfield(**defaults)

    def to_python(self, value):
        def convert(val):
            domain_name_validator(value)
            pattern = re.compile(r"https?://(www\.)?")
            result = pattern.sub('', val).strip().strip('/')
            return result

        if isinstance(value, str) or value is None:
            return convert(value)
        return convert(str(value))


if django.VERSION < (1, 8):
    from django.utils.six import add_metaclass
    MACAddressField = add_metaclass(models.SubfieldBase)(DomainNameField)