From 7109374d42fbdbadb4d1cafbe364590b0a988e1b Mon Sep 17 00:00:00 2001 From: Micah Jerome Ellison Date: Sat, 21 Aug 2021 14:42:31 -0700 Subject: [PATCH] Fix failure to import into directory journal (#1314) * Re-enable failing directory journal import tests * Appropriately track journal name and modified entries in FolderJournal when importing * Run make format --- jrnl/FolderJournal.py | 8 +++++--- jrnl/Journal.py | 10 ++++++---- tests/bdd/features/import.feature | 6 +++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/jrnl/FolderJournal.py b/jrnl/FolderJournal.py index 0c67a141..23fdebd9 100644 --- a/jrnl/FolderJournal.py +++ b/jrnl/FolderJournal.py @@ -22,11 +22,11 @@ def get_files(journal_config): class Folder(Journal.Journal): """A Journal handling multiple files in a folder""" - def __init__(self, **kwargs): + def __init__(self, name="default", **kwargs): self.entries = [] self._diff_entry_dates = [] self.can_be_encrypted = False - super(Folder, self).__init__(**kwargs) + super().__init__(name, **kwargs) def open(self): filenames = [] @@ -44,10 +44,12 @@ class Folder(Journal.Journal): # Create a list of dates of modified entries. Start with diff_entry_dates modified_dates = self._diff_entry_dates seen_dates = set(self._diff_entry_dates) + for e in self.entries: if e.modified: - if e.date not in seen_dates: + if e.date not in modified_dates: modified_dates.append(e.date) + if e.date not in seen_dates: seen_dates.add(e.date) # For every date that had a modified entry, write to a file diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 6d3c6886..b0cadf06 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -67,9 +67,11 @@ class Journal: return new_journal def import_(self, other_journal_txt): - self.entries = list( - frozenset(self.entries) | frozenset(self._parse(other_journal_txt)) - ) + imported_entries = self._parse(other_journal_txt) + for entry in imported_entries: + entry.modified = True + + self.entries = list(frozenset(self.entries) | frozenset(imported_entries)) self.sort() def open(self, filename=None): @@ -414,7 +416,7 @@ def open_journal(journal_name, config, legacy=False): else: from . import FolderJournal - return FolderJournal.Folder(**config).open() + return FolderJournal.Folder(journal_name, **config).open() if not config["encrypt"]: if legacy: diff --git a/tests/bdd/features/import.feature b/tests/bdd/features/import.feature index d75d6017..920cddf2 100644 --- a/tests/bdd/features/import.feature +++ b/tests/bdd/features/import.feature @@ -11,7 +11,7 @@ Feature: Importing data | config_file | | basic_onefile.yaml | | basic_encrypted.yaml | - # | basic_folder.yaml | @todo + | basic_folder.yaml | # | basic_dayone.yaml | @todo Scenario Outline: --import allows new large entry from stdin @@ -34,7 +34,7 @@ Feature: Importing data | config_file | | basic_onefile.yaml | | basic_encrypted.yaml | - # | basic_folder.yaml | @todo + | basic_folder.yaml | # | basic_dayone.yaml | @todo Scenario Outline: --import allows multiple new entries from stdin @@ -56,7 +56,7 @@ Feature: Importing data | config_file | | basic_onefile.yaml | | basic_encrypted.yaml | - # | basic_folder.yaml | @todo + | basic_folder.yaml | # | basic_dayone.yaml | @todo Scenario: --import allows import new entries from file