我们从Python开源项目中,提取了以下40个代码示例,用于说明如何使用django.forms.FilePathField()。
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)
def check(self, **kwargs): errors = super(FilePathField, self).check(**kwargs) errors.extend(self._check_allowing_files_or_folders(**kwargs)) return errors
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
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)
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)
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...
def __init__(self, path, match=None, recursive=False, allow_files=True, allow_folders=False, required=None, **kwargs): # Defer to Django's FilePathField implmentation 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...
def __init__(self, *args, **kwargs): super(Search, self).__init__(*args, **kwargs) self.fields['playbook'] = forms.FilePathField(path=settings.ANSIBLE_PLAYBOOKS_PATH, match='.*\.yml$', required=False, widget=forms.Select(attrs={'class': 'need-select2'}))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['ansible_user'].initial = models.AnsibleUser.objects.first() self.fields['playbook'] = forms.FilePathField(path=settings.ANSIBLE_PLAYBOOKS_PATH, match='.*\.yml$', widget=forms.Select(attrs={'class': 'need-select2'}))
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