Beispiel #1
0
    def on_action_new_note_triggered(self):
        '''
        ..todo: Add multi account support - Select target account for new notes
        '''
        if self.list_widget_notelist.currentRow() >= 0 and\
                (self.line_edit_subject.isModified() or self.text_edit_editor.document().isModified()):
            self.on_action_save_note_triggered()

        note = Note(account_id=self._account_manager.get_account(
            self._account_manager.list_accounts()[0]).id,
                    title='New Note')

        if not self.list_widget_notelist.currentItem(
        ) and self.list_widget_notelist.count() <= 0:
            if self.line_edit_subject.isModified() and len(
                    self.line_edit_subject.text().strip()) > 0:
                note.title = self.line_edit_subject.text()
            if self.text_edit_editor.document().isModified() and len(
                    self.text_edit_editor.document().toPlainText().strip(
                    )) > 0:
                note.html_content = self.text_edit_editor.document().toHtml()

        note.create()

        self.__load_note_to_list(note.account_id, note.file)

        self.list_widget_notelist.setCurrentRow(0)
Beispiel #2
0
    def on_action_duplicate_note_triggered(self):
        if self.line_edit_subject.isModified(
        ) or self.text_edit_editor.document().isModified():
            self.on_action_save_note_triggered()

        note = Note(account_id=self._account_manager.get_account(
            self._account_manager.list_accounts()[0]).id,
                    title='{} (Copy)'.format(self.line_edit_subject.text()),
                    html_content=self.text_edit_editor.toHtml())

        note.create()

        self.__load_note_to_list(note.account_id, note.file)

        self.list_widget_notelist.setCurrentRow(0)
Beispiel #3
0
def create_note(token):
    user_data = decode_token(token)
    note_json = request.json

    # Validation of data
    try:
        note_data = note_schema.load(note_json).data
    except ValidationError as err:
        response.status = 422
        return {"error": err.messages}

    # Checking if note already exists
    try:
        Note.find_by_title(note_data['title'])
        message = "A note with that title already exists"
        response.status = 400
        return {"error": message}
    except:
        note = Note.create(user=user_data['identity'], **note_data)
        return {"note": note_schema.dump(note).data}