本文整理汇总了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...