Python django.forms.SlugField() Examples

The following are 30 code examples of django.forms.SlugField(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.forms , or try the search function .
Example #1
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_modelformset_factory_field_class_overrides(self):
        author = Author.objects.create(pk=1, name='Charles Baudelaire')
        BookFormSet = modelformset_factory(Book, fields="__all__", field_classes={
            'title': forms.SlugField,
        })
        form = BookFormSet.form(data={'title': 'Foo ' * 30, 'author': author.id})
        self.assertIs(Book._meta.get_field('title').__class__, models.CharField)
        self.assertIsInstance(form.fields['title'], forms.SlugField) 
Example #2
Source File: __init__.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        kwargs['max_length'] = kwargs.get('max_length', 50)
        # Set db_index=True unless it's been set manually.
        if 'db_index' not in kwargs:
            kwargs['db_index'] = True
        super(SlugField, self).__init__(*args, **kwargs) 
Example #3
Source File: __init__.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def get_internal_type(self):
        return "SlugField" 
Example #4
Source File: __init__.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField, 'allow_unicode': self.allow_unicode}
        defaults.update(kwargs)
        return super(SlugField, self).formfield(**defaults) 
Example #5
Source File: __init__.py    From python2017 with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        kwargs['max_length'] = kwargs.get('max_length', 50)
        # Set db_index=True unless it's been set manually.
        if 'db_index' not in kwargs:
            kwargs['db_index'] = True
        self.allow_unicode = kwargs.pop('allow_unicode', False)
        if self.allow_unicode:
            self.default_validators = [validators.validate_unicode_slug]
        super(SlugField, self).__init__(*args, **kwargs) 
Example #6
Source File: __init__.py    From python2017 with MIT License 5 votes vote down vote up
def deconstruct(self):
        name, path, args, kwargs = super(SlugField, self).deconstruct()
        if kwargs.get("max_length") == 50:
            del kwargs['max_length']
        if self.db_index is False:
            kwargs['db_index'] = False
        else:
            del kwargs['db_index']
        if self.allow_unicode is not False:
            kwargs['allow_unicode'] = self.allow_unicode
        return name, path, args, kwargs 
Example #7
Source File: __init__.py    From python2017 with MIT License 5 votes vote down vote up
def get_internal_type(self):
        return "SlugField" 
Example #8
Source File: __init__.py    From python2017 with MIT License 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField, 'allow_unicode': self.allow_unicode}
        defaults.update(kwargs)
        return super(SlugField, self).formfield(**defaults) 
Example #9
Source File: test_converter.py    From graphene-django with MIT License 5 votes vote down vote up
def test_should_slug_convert_string():
    assert_conversion(forms.SlugField, String) 
Example #10
Source File: __init__.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def deconstruct(self):
        name, path, args, kwargs = super(SlugField, self).deconstruct()
        if kwargs.get("max_length") == 50:
            del kwargs['max_length']
        if self.db_index is False:
            kwargs['db_index'] = False
        else:
            del kwargs['db_index']
        if self.allow_unicode is not False:
            kwargs['allow_unicode'] = self.allow_unicode
        return name, path, args, kwargs 
Example #11
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_inlineformset_factory_field_class_overrides(self):
        author = Author.objects.create(pk=1, name='Charles Baudelaire')
        BookFormSet = inlineformset_factory(Author, Book, fields="__all__", field_classes={
            'title': forms.SlugField,
        })
        form = BookFormSet.form(data={'title': 'Foo ' * 30, 'author': author.id})
        self.assertIs(Book._meta.get_field('title').__class__, models.CharField)
        self.assertIsInstance(form.fields['title'], forms.SlugField) 
Example #12
Source File: test_slugfield.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_slugfield_normalization(self):
        f = SlugField()
        self.assertEqual(f.clean('    aa-bb-cc    '), 'aa-bb-cc') 
Example #13
Source File: test_slugfield.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_slugfield_unicode_normalization(self):
        f = SlugField(allow_unicode=True)
        self.assertEqual(f.clean('a'), 'a')
        self.assertEqual(f.clean('1'), '1')
        self.assertEqual(f.clean('a1'), 'a1')
        self.assertEqual(f.clean('你好'), '你好')
        self.assertEqual(f.clean('  你-好  '), '你-好')
        self.assertEqual(f.clean('ıçğüş'), 'ıçğüş')
        self.assertEqual(f.clean('foo-ıç-bar'), 'foo-ıç-bar') 
Example #14
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_modelformset_factory_field_class_overrides(self):
        author = Author.objects.create(pk=1, name='Charles Baudelaire')
        BookFormSet = modelformset_factory(Book, fields="__all__", field_classes={
            'title': forms.SlugField,
        })
        form = BookFormSet.form(data={'title': 'Foo ' * 30, 'author': author.id})
        self.assertIs(Book._meta.get_field('title').__class__, models.CharField)
        self.assertIsInstance(form.fields['title'], forms.SlugField) 
Example #15
Source File: test_slugfield.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_slugfield_normalization(self):
        f = SlugField()
        self.assertEqual(f.clean('    aa-bb-cc    '), 'aa-bb-cc') 
Example #16
Source File: test_slugfield.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_slugfield_unicode_normalization(self):
        f = SlugField(allow_unicode=True)
        self.assertEqual(f.clean('a'), 'a')
        self.assertEqual(f.clean('1'), '1')
        self.assertEqual(f.clean('a1'), 'a1')
        self.assertEqual(f.clean('你好'), '你好')
        self.assertEqual(f.clean('  你-好  '), '你-好')
        self.assertEqual(f.clean('ıçğüş'), 'ıçğüş')
        self.assertEqual(f.clean('foo-ıç-bar'), 'foo-ıç-bar') 
Example #17
Source File: fields.py    From esdc-ce with Apache License 2.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(SlugField, self).__init__(*args, **kwargs) 
Example #18
Source File: __init__.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField}
        defaults.update(kwargs)
        return super(SlugField, self).formfield(**defaults) 
Example #19
Source File: __init__.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def deconstruct(self):
        name, path, args, kwargs = super(SlugField, self).deconstruct()
        if kwargs.get("max_length", None) == 50:
            del kwargs['max_length']
        if self.db_index is False:
            kwargs['db_index'] = False
        else:
            del kwargs['db_index']
        return name, path, args, kwargs 
Example #20
Source File: __init__.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def get_internal_type(self):
        return "SlugField" 
Example #21
Source File: __init__.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField}
        defaults.update(kwargs)
        return super(SlugField, self).formfield(**defaults) 
Example #22
Source File: __init__.py    From bioforum with MIT License 5 votes vote down vote up
def get_internal_type(self):
        return "SlugField" 
Example #23
Source File: __init__.py    From bioforum with MIT License 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField, 'allow_unicode': self.allow_unicode}
        defaults.update(kwargs)
        return super().formfield(**defaults) 
Example #24
Source File: __init__.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def get_internal_type(self):
        return "SlugField" 
Example #25
Source File: __init__.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def formfield(self, **kwargs):
        return super().formfield(**{
            'form_class': forms.SlugField,
            'allow_unicode': self.allow_unicode,
            **kwargs,
        }) 
Example #26
Source File: __init__.py    From python with Apache License 2.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        kwargs['max_length'] = kwargs.get('max_length', 50)
        # Set db_index=True unless it's been set manually.
        if 'db_index' not in kwargs:
            kwargs['db_index'] = True
        self.allow_unicode = kwargs.pop('allow_unicode', False)
        if self.allow_unicode:
            self.default_validators = [validators.validate_unicode_slug]
        super(SlugField, self).__init__(*args, **kwargs) 
Example #27
Source File: __init__.py    From python with Apache License 2.0 5 votes vote down vote up
def deconstruct(self):
        name, path, args, kwargs = super(SlugField, self).deconstruct()
        if kwargs.get("max_length") == 50:
            del kwargs['max_length']
        if self.db_index is False:
            kwargs['db_index'] = False
        else:
            del kwargs['db_index']
        if self.allow_unicode is not False:
            kwargs['allow_unicode'] = self.allow_unicode
        return name, path, args, kwargs 
Example #28
Source File: __init__.py    From python with Apache License 2.0 5 votes vote down vote up
def get_internal_type(self):
        return "SlugField" 
Example #29
Source File: __init__.py    From python with Apache License 2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {'form_class': forms.SlugField, 'allow_unicode': self.allow_unicode}
        defaults.update(kwargs)
        return super(SlugField, self).formfield(**defaults) 
Example #30
Source File: __init__.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        kwargs['max_length'] = kwargs.get('max_length', 50)
        # Set db_index=True unless it's been set manually.
        if 'db_index' not in kwargs:
            kwargs['db_index'] = True
        super(SlugField, self).__init__(*args, **kwargs)