def add(self, note): """ The note lastModified time is updated from Dropbox when the operations succeeds (unfortunately there's no way to set the modified time in Dropbox). """ uuid= note.uuid result= self.__client.put_file(self.__notePath(uuid), marshalNote(note)) if len(result["path"]) != len(self.__notePath(uuid)): try: self.__client.file_delete(result["path"]) except ErrorResponse: pass raise RuntimeError("Note[uuid=%s] already exists" % uuid) note.lastModified= getLastModified(result) if note.photo: self.__client.put_file(self.__photoPath(uuid), note.photo, overwrite=True) elif uuid in self.__notesCache and self.__notesCache[uuid].hasPhoto: try: self.__client.file_delete(self.__photoPath(uuid)) except ErrorResponse: pass renderHtml(note) #Clean removed note if exists if uuid in self.__notesCache and self.__notesCache[uuid].removed: try: self.__client.file_delete(self.__removedNotePath(uuid)) except ErrorResponse: pass
def inflateNote(notePath, photoPath=None, withoutText=False): with open(notePath, "rb") as file: note = readNote(file, getModifiedOn(notePath), withoutText) if photoPath and isfile(photoPath): with open(photoPath, "rb") as file: note.photo = file.read() return renderHtml(note)
def __onConfirm(self, note): parent = self.__parentWindow if not note.title: parent.showError("A title is required") raise ValidationError noteProvider = parent.noteProvider() if note.uuid: noteProvider.update(renderHtml(note)) else: note.uuid = newUuid() note.createdOn = note.lastModified noteProvider.add(renderHtml(note)) self.__note = note parent.reload(True, True) parent.showStatus("Note saved")
def __onConfirm(self, note): parent= self.__parentWindow if not note.title: parent.showError("A title is required") raise ValidationError noteProvider= parent.noteProvider() if note.uuid: noteProvider.update(renderHtml(note)) else: note.uuid= uuid() note.createdOn= note.lastModified noteProvider.add(renderHtml(note)) self.__note= note parent.reload(True, True) parent.showStatus("Note saved")
def inflateNote(notePath, photoPath=None, withoutText=False): with open(notePath, "rb") as file: note= readNote(file, getModifiedOn(notePath), withoutText) if photoPath and isfile(photoPath): with open(photoPath, "rb") as file: note.photo= file.read() return renderHtml(note)
def get(self, uuid): ns= self.__noteStatusCache.get(uuid) if not ns or ns.removed: raise RuntimeError("Note[uuid=%s] does not exist" % uuid) content= self._service().get_media(fileId=ns.noteId).execute() note= unmarshalNote(content, ns.lastModified) if ns.hasPhoto: note.photo= self._service().get_media(fileId=ns.photoId).execute() return renderHtml(note)
def get(self, uuid): ns = self.__noteStatusCache.get(uuid) if not ns or ns.removed: raise RuntimeError("Note[uuid=%s] does not exist" % uuid) _LOG.info("Getting note: %s", uuid) content = self._service().get_media(fileId=ns.noteId).execute() note = unmarshalNote(content, ns.lastModified) if ns.hasPhoto: _LOG.info("Getting photo: %s", uuid) note.photo = self._service().get_media(fileId=ns.photoId).execute() return renderHtml(note)
def update(self, note): """ The note lastModified time is updated from Dropbox when the operations succeeds (unfortunately there's no way to set the modified time in Dropbox). """ uuid= note.uuid #Check if note exists if self.__notesCache and (uuid not in self.__notesCache or self.__notesCache[uuid].removed): raise RuntimeError("Note[uuid=%s] does not exist" % uuid) result= self.__client.put_file(self.__notePath(uuid), marshalNote(note), overwrite=True) note.lastModified= getLastModified(result) if note.photo: self.__client.put_file(self.__photoPath(uuid), note.photo, overwrite=True) elif uuid not in self.__notesCache or self.__notesCache[uuid].hasPhoto: try: self.__client.file_delete(self.__photoPath(uuid)) except ErrorResponse: pass renderHtml(note)
def get(self, uuid): response, metadata= self.__client.get_file_and_metadata(self.__notePath(uuid)) with response: note= unmarshalNote(response.read(), getLastModified(metadata)) if uuid not in self.__notesCache or self.__notesCache[uuid].hasPhoto: try: with self.__client.get_file(self.__photoPath(uuid)) as response: note.photo= response.read() except ErrorResponse as e: if e.status == 404: #Photo does not exist pass else: raise e return renderHtml(note)
def get(self, uuid): _LOG.info("Getting note: %s", uuid) metadata, response = self.__client.files_download(self.__notePath(uuid)) with response: note = unmarshalNote(response.content, metadata.client_modified) if uuid not in self.__notesCache or self.__notesCache[uuid].hasPhoto: _LOG.info("Getting photo: %s", uuid) try: with self.__client.files_download(self.__photoPath(uuid))[1] as response: note.photo = response.content except ApiError as e: if e.error.is_path() and e.error.get_path().is_not_found(): _LOG.warning("Photo %s does not exist", uuid) else: raise e return renderHtml(note)
def testRenderHtmlShouldSucceed(self): note = Note(title="Some title", tags=["one", "two"], text="Hello, **world**!") renderHtml(note) self.assertIn("<p>Hello, <strong>world</strong>!</p>", note.html)
def __onNewNoteClicked(self): if self.__viewerEditor.isAllowedToChange(): self.__lstNotes.setCurrentItem(None) self.__viewerEditor.edit(renderHtml(Note())) self.__refreshNoteButtons()
def __refreshNoteViewerEditor(self): if self.__selectedItem(): note = self.noteProvider().get(self.__selectedItem().note().uuid) else: note = renderHtml(Note()) self.__viewerEditor.view(note)
def __refreshNoteViewerEditor(self): if self.__selectedItem(): note= self.noteProvider().get(self.__selectedItem().note().uuid) else: note= renderHtml(Note()) self.__viewerEditor.view(note)
def testRenderHtmlShouldSucceed(self): note= Note(title="Some title", tags=["one", "two"], text="Hello, **world**!") renderHtml(note) self.assertIn("<p>Hello, <strong>world</strong>!</p>", note.html)