Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failure to import into directory journal #1314

Merged
merged 6 commits into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions jrnl/FolderJournal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -44,10 +44,12 @@ def write(self):
# 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
Expand Down
10 changes: 6 additions & 4 deletions jrnl/Journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ def from_journal(cls, other):
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):
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tests/bdd/features/import.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down