mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-18 03:58:32 +02:00
Appropriately track journal name and modified entries in FolderJournal when importing
This commit is contained in:
parent
7cdba42dbc
commit
076674f993
2 changed files with 11 additions and 5 deletions
|
@ -22,10 +22,10 @@ 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 = []
|
||||
super(Folder, self).__init__(**kwargs)
|
||||
super().__init__(name, **kwargs)
|
||||
|
||||
def open(self):
|
||||
filenames = []
|
||||
|
@ -43,10 +43,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
|
||||
|
|
|
@ -67,11 +67,15 @@ class Journal:
|
|||
return new_journal
|
||||
|
||||
def import_(self, 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(self._parse(other_journal_txt))
|
||||
frozenset(self.entries) | frozenset(imported_entries)
|
||||
)
|
||||
self.sort()
|
||||
|
||||
|
||||
def open(self, filename=None):
|
||||
"""Opens the journal file defined in the config and parses it into a list of Entries.
|
||||
Entries have the form (date, title, body)."""
|
||||
|
@ -414,7 +418,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:
|
||||
|
|
Loading…
Add table
Reference in a new issue