Python django.forms.FilePathField() Examples

The following are 30 code examples of django.forms.FilePathField(). 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: test_filepathfield.py    From djongo with 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
Source File: test_filepathfield.py    From djongo with 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
Source File: test_filepathfield.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_match(self):
        f = FilePathField(path=self.path, match=r'^.*?\.py$')
        self.assertChoices(f, self.expected_choices[:4]) 
Example #4
Source File: __init__.py    From openhgsenti with 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 #5
Source File: __init__.py    From python2017 with 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 #6
Source File: __init__.py    From python2017 with 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 #7
Source File: __init__.py    From python2017 with 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 #8
Source File: __init__.py    From python2017 with 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 #9
Source File: __init__.py    From python2017 with 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 #10
Source File: fields.py    From Dailyfresh-B2C with 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... 
Example #11
Source File: test_filepathfield.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_no_options(self):
        f = FilePathField(path=self.path)
        expected = [
            ('/filepathfield_test_dir/README', 'README'),
        ] + self.expected_choices[:4]
        self.assertChoices(f, expected) 
Example #12
Source File: test_filepathfield.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_clean(self):
        f = FilePathField(path=self.path)
        msg = "'Select a valid choice. a.py is not one of the available choices.'"
        with self.assertRaisesMessage(ValidationError, msg):
            f.clean('a.py')
        self.assertEqual(fix_os_paths(f.clean(self.path + 'a.py')), '/filepathfield_test_dir/a.py') 
Example #13
Source File: __init__.py    From openhgsenti with 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 #14
Source File: test_filepathfield.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_allow_folders(self):
        f = FilePathField(path=self.path, allow_folders=True, allow_files=False)
        self.assertChoices(f, [
            ('/filepathfield_test_dir/c', 'c'),
            ('/filepathfield_test_dir/h', 'h'),
            ('/filepathfield_test_dir/j', 'j'),
        ]) 
Example #15
Source File: test_filepathfield.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_recursive_folders_without_files(self):
        f = FilePathField(path=self.path, recursive=True, allow_folders=True, allow_files=False)
        self.assertChoices(f, [
            ('/filepathfield_test_dir/c', 'c'),
            ('/filepathfield_test_dir/h', 'h'),
            ('/filepathfield_test_dir/j', 'j'),
            ('/filepathfield_test_dir/c/f', 'c/f'),
        ]) 
Example #16
Source File: test_filepathfield.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_no_options(self):
        f = FilePathField(path=self.path)
        expected = [
            ('/filepathfield_test_dir/README', 'README'),
        ] + self.expected_choices[:4]
        self.assertChoices(f, expected) 
Example #17
Source File: test_filepathfield.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_clean(self):
        f = FilePathField(path=self.path)
        msg = "'Select a valid choice. a.py is not one of the available choices.'"
        with self.assertRaisesMessage(ValidationError, msg):
            f.clean('a.py')
        self.assertEqual(fix_os_paths(f.clean(self.path + 'a.py')), '/filepathfield_test_dir/a.py') 
Example #18
Source File: test_filepathfield.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_match(self):
        f = FilePathField(path=self.path, match=r'^.*?\.py$')
        self.assertChoices(f, self.expected_choices[:4]) 
Example #19
Source File: test_filepathfield.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_recursive_no_folders_or_files(self):
        f = FilePathField(path=self.path, recursive=True, allow_folders=False, allow_files=False)
        self.assertChoices(f, []) 
Example #20
Source File: test_filepathfield.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_recursive_folders_without_files(self):
        f = FilePathField(path=self.path, recursive=True, allow_folders=True, allow_files=False)
        self.assertChoices(f, [
            ('/filepathfield_test_dir/c', 'c'),
            ('/filepathfield_test_dir/h', 'h'),
            ('/filepathfield_test_dir/j', 'j'),
            ('/filepathfield_test_dir/c/f', 'c/f'),
        ]) 
Example #21
Source File: __init__.py    From python with 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 #22
Source File: __init__.py    From GTDWeb with 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 #23
Source File: __init__.py    From GTDWeb with 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 #24
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(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 #25
Source File: __init__.py    From GTDWeb with 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 #26
Source File: __init__.py    From GTDWeb with 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 #27
Source File: __init__.py    From bioforum with 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 #28
Source File: __init__.py    From bioforum with MIT License 5 votes vote down vote up
def get_internal_type(self):
        return "FilePathField" 
Example #29
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(**{
            '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 #30
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 "FilePathField"