def _delete_files(self, item): for file_col in self.get_file_column_list(): if self.is_file(file_col): if getattr(item, file_col): fm = FileManager() fm.delete_file(getattr(item, file_col)) for file_col in self.get_image_column_list(): if self.is_image(file_col): if getattr(item, file_col): im = ImageManager() im.delete_file(getattr(item, file_col))
def _add_files(self, this_request, item): fm = FileManager() im = ImageManager() for file_col in this_request.files: if self.is_file(file_col): fm.save_file(this_request.files[file_col], getattr(item, file_col)) for file_col in this_request.files: if self.is_image(file_col): im.save_file(this_request.files[file_col], getattr(item, file_col))
def __init__(self, label=None, validators=None, filemanager=None, **kwargs): """ Constructor. :param label: Display label :param validators: Validators """ self.filemanager = filemanager or FileManager() self._should_delete = False super(FileUploadField, self).__init__(label, validators, **kwargs)