Python django.forms.FilePathField() Examples

The following are 30 code examples for showing how to use django.forms.FilePathField(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.forms , or try the search function .

Example 1
Project: djongo   Author: nesdis   File: test_filepathfield.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def test_recursive(self):
        f = FilePathField(path=self.path, recursive=True, match=r'^.*?\.py$')
        expected = [
            ('/filepathfield_test_dir/__init__.py', '__init__.py'),
            ('/filepathfield_test_dir/a.py', 'a.py'),
            ('/filepathfield_test_dir/ab.py', 'ab.py'),
            ('/filepathfield_test_dir/b.py', 'b.py'),
            ('/filepathfield_test_dir/c/__init__.py', 'c/__init__.py'),
            ('/filepathfield_test_dir/c/d.py', 'c/d.py'),
            ('/filepathfield_test_dir/c/e.py', 'c/e.py'),
            ('/filepathfield_test_dir/c/f/__init__.py', 'c/f/__init__.py'),
            ('/filepathfield_test_dir/c/f/g.py', 'c/f/g.py'),
            ('/filepathfield_test_dir/h/__init__.py', 'h/__init__.py'),
            ('/filepathfield_test_dir/j/__init__.py', 'j/__init__.py'),

        ]
        self.assertChoices(f, expected) 
Example 2
Project: djongo   Author: nesdis   File: test_filepathfield.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def test_recursive(self):
        f = FilePathField(path=self.path, recursive=True, match=r'^.*?\.py$')
        expected = [
            ('/filepathfield_test_dir/__init__.py', '__init__.py'),
            ('/filepathfield_test_dir/a.py', 'a.py'),
            ('/filepathfield_test_dir/ab.py', 'ab.py'),
            ('/filepathfield_test_dir/b.py', 'b.py'),
            ('/filepathfield_test_dir/c/__init__.py', 'c/__init__.py'),
            ('/filepathfield_test_dir/c/d.py', 'c/d.py'),
            ('/filepathfield_test_dir/c/e.py', 'c/e.py'),
            ('/filepathfield_test_dir/c/f/__init__.py', 'c/f/__init__.py'),
            ('/filepathfield_test_dir/c/f/g.py', 'c/f/g.py'),
            ('/filepathfield_test_dir/h/__init__.py', 'h/__init__.py'),
            ('/filepathfield_test_dir/j/__init__.py', 'j/__init__.py'),

        ]
        self.assertChoices(f, expected) 
Example 3
Project: ideascube   Author: ideascube   File: forms.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, path, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['original'] = forms.FilePathField(
            path=path, recursive=True)
        self.fields['preview'] = forms.FilePathField(
            path=path, recursive=True, required=False) 
Example 4
Project: GTDWeb   Author: lanbing510   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, verbose_name=None, name=None, path='', match=None,
                 recursive=False, allow_files=True, allow_folders=False, **kwargs):
        self.path, self.match, self.recursive = path, match, recursive
        self.allow_files, self.allow_folders = allow_files, allow_folders
        kwargs['max_length'] = kwargs.get('max_length', 100)
        super(FilePathField, self).__init__(verbose_name, name, **kwargs) 
Example 5
Project: GTDWeb   Author: lanbing510   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def check(self, **kwargs):
        errors = super(FilePathField, self).check(**kwargs)
        errors.extend(self._check_allowing_files_or_folders(**kwargs))
        return errors 
Example 6
Project: GTDWeb   Author: lanbing510   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def deconstruct(self):
        name, path, args, kwargs = super(FilePathField, self).deconstruct()
        if self.path != '':
            kwargs['path'] = self.path
        if self.match is not None:
            kwargs['match'] = self.match
        if self.recursive is not False:
            kwargs['recursive'] = self.recursive
        if self.allow_files is not True:
            kwargs['allow_files'] = self.allow_files
        if self.allow_folders is not False:
            kwargs['allow_folders'] = self.allow_folders
        if kwargs.get("max_length", None) == 100:
            del kwargs["max_length"]
        return name, path, args, kwargs 
Example 7
Project: GTDWeb   Author: lanbing510   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def get_prep_value(self, value):
        value = super(FilePathField, self).get_prep_value(value)
        if value is None:
            return None
        return six.text_type(value) 
Example 8
Project: GTDWeb   Author: lanbing510   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {
            'path': self.path,
            'match': self.match,
            'recursive': self.recursive,
            'form_class': forms.FilePathField,
            'allow_files': self.allow_files,
            'allow_folders': self.allow_folders,
        }
        defaults.update(kwargs)
        return super(FilePathField, self).formfield(**defaults) 
Example 9
Project: bioforum   Author: reBiocoder   File: __init__.py    License: MIT License 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {
            'path': self.path,
            'match': self.match,
            'recursive': self.recursive,
            'form_class': forms.FilePathField,
            'allow_files': self.allow_files,
            'allow_folders': self.allow_folders,
        }
        defaults.update(kwargs)
        return super().formfield(**defaults) 
Example 10
Project: bioforum   Author: reBiocoder   File: __init__.py    License: MIT License 5 votes vote down vote up
def get_internal_type(self):
        return "FilePathField" 
Example 11
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: __init__.py    License: MIT License 5 votes vote down vote up
def formfield(self, **kwargs):
        return super().formfield(**{
            'path': self.path,
            'match': self.match,
            'recursive': self.recursive,
            'form_class': forms.FilePathField,
            'allow_files': self.allow_files,
            'allow_folders': self.allow_folders,
            **kwargs,
        }) 
Example 12
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: __init__.py    License: MIT License 5 votes vote down vote up
def get_internal_type(self):
        return "FilePathField" 
Example 13
Project: python   Author: Yeah-Kun   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, verbose_name=None, name=None, path='', match=None,
                 recursive=False, allow_files=True, allow_folders=False, **kwargs):
        self.path, self.match, self.recursive = path, match, recursive
        self.allow_files, self.allow_folders = allow_files, allow_folders
        kwargs['max_length'] = kwargs.get('max_length', 100)
        super(FilePathField, self).__init__(verbose_name, name, **kwargs) 
Example 14
Project: python   Author: Yeah-Kun   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def check(self, **kwargs):
        errors = super(FilePathField, self).check(**kwargs)
        errors.extend(self._check_allowing_files_or_folders(**kwargs))
        return errors 
Example 15
Project: python   Author: Yeah-Kun   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def deconstruct(self):
        name, path, args, kwargs = super(FilePathField, self).deconstruct()
        if self.path != '':
            kwargs['path'] = self.path
        if self.match is not None:
            kwargs['match'] = self.match
        if self.recursive is not False:
            kwargs['recursive'] = self.recursive
        if self.allow_files is not True:
            kwargs['allow_files'] = self.allow_files
        if self.allow_folders is not False:
            kwargs['allow_folders'] = self.allow_folders
        if kwargs.get("max_length") == 100:
            del kwargs["max_length"]
        return name, path, args, kwargs 
Example 16
Project: python   Author: Yeah-Kun   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def get_prep_value(self, value):
        value = super(FilePathField, self).get_prep_value(value)
        if value is None:
            return None
        return six.text_type(value) 
Example 17
Project: python   Author: Yeah-Kun   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {
            'path': self.path,
            'match': self.match,
            'recursive': self.recursive,
            'form_class': forms.FilePathField,
            'allow_files': self.allow_files,
            'allow_folders': self.allow_folders,
        }
        defaults.update(kwargs)
        return super(FilePathField, self).formfield(**defaults) 
Example 18
Project: luscan-devel   Author: blackye   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {
            'path': self.path,
            'match': self.match,
            'recursive': self.recursive,
            'form_class': forms.FilePathField,
            'allow_files': self.allow_files,
            'allow_folders': self.allow_folders,
        }
        defaults.update(kwargs)
        return super(FilePathField, self).formfield(**defaults) 
Example 19
Project: luscan-devel   Author: blackye   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def get_internal_type(self):
        return "FilePathField" 
Example 20
Project: openhgsenti   Author: drexly   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, verbose_name=None, name=None, path='', match=None,
                 recursive=False, allow_files=True, allow_folders=False, **kwargs):
        self.path, self.match, self.recursive = path, match, recursive
        self.allow_files, self.allow_folders = allow_files, allow_folders
        kwargs['max_length'] = kwargs.get('max_length', 100)
        super(FilePathField, self).__init__(verbose_name, name, **kwargs) 
Example 21
Project: openhgsenti   Author: drexly   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def check(self, **kwargs):
        errors = super(FilePathField, self).check(**kwargs)
        errors.extend(self._check_allowing_files_or_folders(**kwargs))
        return errors 
Example 22
Project: openhgsenti   Author: drexly   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def deconstruct(self):
        name, path, args, kwargs = super(FilePathField, self).deconstruct()
        if self.path != '':
            kwargs['path'] = self.path
        if self.match is not None:
            kwargs['match'] = self.match
        if self.recursive is not False:
            kwargs['recursive'] = self.recursive
        if self.allow_files is not True:
            kwargs['allow_files'] = self.allow_files
        if self.allow_folders is not False:
            kwargs['allow_folders'] = self.allow_folders
        if kwargs.get("max_length") == 100:
            del kwargs["max_length"]
        return name, path, args, kwargs 
Example 23
Project: openhgsenti   Author: drexly   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def get_prep_value(self, value):
        value = super(FilePathField, self).get_prep_value(value)
        if value is None:
            return None
        return six.text_type(value) 
Example 24
Project: openhgsenti   Author: drexly   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {
            'path': self.path,
            'match': self.match,
            'recursive': self.recursive,
            'form_class': forms.FilePathField,
            'allow_files': self.allow_files,
            'allow_folders': self.allow_folders,
        }
        defaults.update(kwargs)
        return super(FilePathField, self).formfield(**defaults) 
Example 25
Project: python2017   Author: bpgc-cte   File: __init__.py    License: MIT License 5 votes vote down vote up
def __init__(self, verbose_name=None, name=None, path='', match=None,
                 recursive=False, allow_files=True, allow_folders=False, **kwargs):
        self.path, self.match, self.recursive = path, match, recursive
        self.allow_files, self.allow_folders = allow_files, allow_folders
        kwargs['max_length'] = kwargs.get('max_length', 100)
        super(FilePathField, self).__init__(verbose_name, name, **kwargs) 
Example 26
Project: python2017   Author: bpgc-cte   File: __init__.py    License: MIT License 5 votes vote down vote up
def check(self, **kwargs):
        errors = super(FilePathField, self).check(**kwargs)
        errors.extend(self._check_allowing_files_or_folders(**kwargs))
        return errors 
Example 27
Project: python2017   Author: bpgc-cte   File: __init__.py    License: MIT License 5 votes vote down vote up
def deconstruct(self):
        name, path, args, kwargs = super(FilePathField, self).deconstruct()
        if self.path != '':
            kwargs['path'] = self.path
        if self.match is not None:
            kwargs['match'] = self.match
        if self.recursive is not False:
            kwargs['recursive'] = self.recursive
        if self.allow_files is not True:
            kwargs['allow_files'] = self.allow_files
        if self.allow_folders is not False:
            kwargs['allow_folders'] = self.allow_folders
        if kwargs.get("max_length") == 100:
            del kwargs["max_length"]
        return name, path, args, kwargs 
Example 28
Project: python2017   Author: bpgc-cte   File: __init__.py    License: MIT License 5 votes vote down vote up
def get_prep_value(self, value):
        value = super(FilePathField, self).get_prep_value(value)
        if value is None:
            return None
        return six.text_type(value) 
Example 29
Project: python2017   Author: bpgc-cte   File: __init__.py    License: MIT License 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {
            'path': self.path,
            'match': self.match,
            'recursive': self.recursive,
            'form_class': forms.FilePathField,
            'allow_files': self.allow_files,
            'allow_folders': self.allow_folders,
        }
        defaults.update(kwargs)
        return super(FilePathField, self).formfield(**defaults) 
Example 30
Project: Dailyfresh-B2C   Author: BeanWei   File: fields.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, path, match=None, recursive=False, allow_files=True,
                 allow_folders=False, required=None, **kwargs):
        # Defer to Django's FilePathField implementation to get the
        # valid set of choices.
        field = DjangoFilePathField(
            path, match=match, recursive=recursive, allow_files=allow_files,
            allow_folders=allow_folders, required=required
        )
        kwargs['choices'] = field.choices
        super(FilePathField, self).__init__(**kwargs)


# File types...