Ejemplo n.º 1
0
    def test_get_changed_content(self):
        notename = list(self.db_notes.keys())[0]
        note = self.db_notes[notename]
        filepath = note.filepath

        # Read data from file, not using NoteModel
        raw_data = NoteModel.enc_read(filepath)
        content, metadata = NoteModel.parse_note_content(raw_data)
        timestamp = os.stat(filepath).st_mtime

        self.assertEqual(note.content, content)
        self.assertEqual(note.timestamp, timestamp)

        # Make a change
        new_content = content + '\nNew line\n'
        self.assertNotEqual(note.content, new_content)

        # Write changed data not from NoteModel
        filedata = new_content + END_OF_TEXT + '\n'
        for key, value in list(metadata.items()):
            filedata = filedata + '{0}:{1}\n'.format(key, value)
        NoteModel.enc_write(filepath, filedata)

        # Change happened?
        self.assertNotEqual(note.timestamp, timestamp)

        # And the content automatically updates when accessed
        self.assertEqual(note.content, new_content)

        # Reset file
        filedata = content + END_OF_TEXT + '\n'
        for key, value in list(metadata.items()):
            filedata = filedata + '{0}:{1}\n'.format(key, value)
        NoteModel.enc_write(filepath, filedata)
Ejemplo n.º 2
0
    def update_ui_views_history(self):
        if self.old_data is None:
            self.update_ui_views()
        else:
            old_content, old_meta = NoteModel.parse_note_content(
                self.old_data[0])
            # update the note editor
            self.noteEditor.blockSignals(True)
            self.noteEditor.set_note_text(old_content)
            self.noteEditor.blockSignals(False)

            # update the tag editor
            self.tagEditor.blockSignals(True)
            try:
                self.tagEditor.setText(old_meta['tags'])
            except (TypeError, KeyError):
                # no metadata or no tag metadata
                self.tagEditor.setText('')
            self.tagEditor.blockSignals(False)

            # update the preview and diff panes
            self.update_ui_preview()
            self.update_ui_diff()

            # update the window title
            dt_str = self.old_data[1]
            dt = history_timestring_to_datetime(dt_str)
            tab_date = '[' + human_date(dt) + ']'
            self.setWindowTitle(' '.join(
                [WINDOW_TITLE, '-', self.current_note.title, tab_date]))
Ejemplo n.º 3
0
 def update_ui_diff(self):
     if self.old_data is not None:
         new_content = self.current_note.content
         content, __ = NoteModel.parse_note_content(self.old_data[0])
         dt_str = self.old_data[1]
         dt = history_timestring_to_datetime(dt_str)
         tab_date = '[' + human_date(dt) + ']'
         fromdesc = ' '.join([self.current_note.title, tab_date])
         diff_html = diff_to_html(content, new_content, fromdesc,
                                  self.current_note.title)
     else:
         try:
             diff_html = self.current_note.get_status()
         except AttributeError:
             # current_note is None
             diff_html = ''
     self.ui.noteDiff.setHtml(diff_html)
     if self.current_note is not None:
         self.ui.noteDiff.setDocumentTitle(
             self.current_note.title)  # for things like print to pdf
     self.ui.noteDiff.reload()
Ejemplo n.º 4
0
def open_and_parse_note(filepath):
    data = NoteModel.enc_read(filepath)
    return NoteModel.parse_note_content(data)
Ejemplo n.º 5
0
def open_and_parse_note(filepath):
    data = NoteModel.enc_read(filepath)
    return NoteModel.parse_note_content(data)