本文整理匯總了Python中django.forms.FilePathField方法的典型用法代碼示例。如果您正苦於以下問題:Python forms.FilePathField方法的具體用法?Python forms.FilePathField怎麽用?Python forms.FilePathField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.forms
的用法示例。
在下文中一共展示了forms.FilePathField方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_recursive
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FilePathField [as 別名]
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)
示例2: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FilePathField [as 別名]
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)
示例3: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FilePathField [as 別名]
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)
示例4: check
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FilePathField [as 別名]
def check(self, **kwargs):
errors = super(FilePathField, self).check(**kwargs)
errors.extend(self._check_allowing_files_or_folders(**kwargs))
return errors
示例5: deconstruct
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FilePathField [as 別名]
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
示例6: get_prep_value
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FilePathField [as 別名]
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)
示例7: formfield
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FilePathField [as 別名]
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)
示例8: formfield
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FilePathField [as 別名]
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)
示例9: get_internal_type
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FilePathField [as 別名]
def get_internal_type(self):
return "FilePathField"
示例10: formfield
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FilePathField [as 別名]
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,
})
示例11: deconstruct
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FilePathField [as 別名]
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
示例12: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FilePathField [as 別名]
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...