def add_attachment(self, filename, fp): """Stores a new attachment. Returns `None` if the file already""" if not self.exists: raise BadEdit('Record does not exist.') if self.is_attachment: raise BadEdit('Cannot attach something to an attachment.') directory = self.pad.db.to_fs_path(self.path) safe_filename = secure_filename(filename) while 1: fn = os.path.join(directory, safe_filename) if not os.path.isfile(fn): break safe_filename = increment_filename(fn) with atomic_open(fn, 'w') as f: shutil.copyfileobj(fp, f) return safe_filename
def add_attachment(self, filename, fp): """Stores a new attachment. Returns `None` if the file already""" if not self.exists: raise BadEdit('Record does not exist.') if self.is_attachment: raise BadEdit('Cannot attach something to an attachment.') directory = self.pad.db.to_fs_path(self.path) safe_filename = secure_filename(filename) while 1: fn = os.path.join(directory, safe_filename) if not os.path.isfile(fn): break safe_filename = increment_filename(fn) with atomic_open(fn, 'wb') as f: shutil.copyfileobj(fp, f) return safe_filename
def add_attachment(self, filename, fp): """Stores a new attachment. Returns `None` if the file already""" if not self.exists: raise BadEdit("Record does not exist.") if self.is_attachment: raise BadEdit("Cannot attach something to an attachment.") if not self.datamodel.has_own_attachments: raise BadEdit("Attachments are disabled for this page.") directory = self.pad.db.to_fs_path(self.path) safe_filename = secure_filename(filename) while 1: fn = os.path.join(directory, safe_filename) if not os.path.isfile(fn): break safe_filename = increment_filename(fn) with atomic_open(fn, "wb") as f: shutil.copyfileobj(fp, f) return safe_filename