def _save_impl(self): if not self._changed and self.exists: return try: os.makedirs(os.path.dirname(self.fs_path)) except OSError: pass with atomic_open(self.fs_path, 'wb') as f: for chunk in serialize(self.iteritems(), encoding='utf-8'): f.write(chunk)
def _save_impl(self): # When creating a new alt from a primary self.exists is True but # the file does not exist yet. In this case we want to explicitly # create it anyways instead of bailing. if not self._changed and self.exists and os.path.exists(self.fs_path): return try: os.makedirs(os.path.dirname(self.fs_path)) except OSError: pass with atomic_open(self.fs_path, 'wb') as f: for chunk in serialize(self.iteritems(), encoding='utf-8'): f.write(chunk)
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.') 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.") 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