mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-12 01:18:31 +02:00
Modified flag for entries
This commit is contained in:
parent
4d8949bbed
commit
e4bc0794f1
2 changed files with 7 additions and 9 deletions
|
@ -13,6 +13,7 @@ class Entry:
|
||||||
self.body = body.strip()
|
self.body = body.strip()
|
||||||
self.tags = self.parse_tags()
|
self.tags = self.parse_tags()
|
||||||
self.starred = starred
|
self.starred = starred
|
||||||
|
self.modified = False
|
||||||
|
|
||||||
def parse_tags(self):
|
def parse_tags(self):
|
||||||
fulltext = " ".join([self.title, self.body]).lower()
|
fulltext = " ".join([self.title, self.body]).lower()
|
||||||
|
|
|
@ -308,6 +308,7 @@ class Journal(object):
|
||||||
if not date: # Still nothing? Meh, just live in the moment.
|
if not date: # Still nothing? Meh, just live in the moment.
|
||||||
date = self.parse_date("now")
|
date = self.parse_date("now")
|
||||||
entry = Entry.Entry(self, date, title, body, starred=starred)
|
entry = Entry.Entry(self, date, title, body, starred=starred)
|
||||||
|
entry.modified = True
|
||||||
self.entries.append(entry)
|
self.entries.append(entry)
|
||||||
if sort:
|
if sort:
|
||||||
self.sort()
|
self.sort()
|
||||||
|
@ -350,21 +351,17 @@ class DayOne(Journal):
|
||||||
def write(self):
|
def write(self):
|
||||||
"""Writes only the entries that have been modified into plist files."""
|
"""Writes only the entries that have been modified into plist files."""
|
||||||
for entry in self.entries:
|
for entry in self.entries:
|
||||||
# Assumption: since jrnl can not manipulate existing entries, all entries
|
if entry.modified:
|
||||||
# that have a uuid will be old ones, and only the one that doesn't will
|
if not hasattr(entry, "uuid"):
|
||||||
# have a new one!
|
entry.uuid = uuid.uuid1().hex
|
||||||
if not hasattr(entry, "uuid"):
|
|
||||||
utc_time = datetime.utcfromtimestamp(time.mktime(entry.date.timetuple()))
|
utc_time = datetime.utcfromtimestamp(time.mktime(entry.date.timetuple()))
|
||||||
new_uuid = uuid.uuid1().hex
|
filename = os.path.join(self.config['journal'], "entries", entry.uuid+".doentry")
|
||||||
filename = os.path.join(self.config['journal'], "entries", new_uuid+".doentry")
|
|
||||||
entry_plist = {
|
entry_plist = {
|
||||||
'Creation Date': utc_time,
|
'Creation Date': utc_time,
|
||||||
'Starred': entry.starred if hasattr(entry, 'starred') else False,
|
'Starred': entry.starred if hasattr(entry, 'starred') else False,
|
||||||
'Entry Text': entry.title+"\n"+entry.body,
|
'Entry Text': entry.title+"\n"+entry.body,
|
||||||
'Time Zone': util.get_local_timezone(),
|
'Time Zone': util.get_local_timezone(),
|
||||||
'UUID': new_uuid,
|
'UUID': entry.uuid,
|
||||||
'Tags': [tag.strip(self.config['tagsymbols']) for tag in entry.tags]
|
'Tags': [tag.strip(self.config['tagsymbols']) for tag in entry.tags]
|
||||||
}
|
}
|
||||||
# print entry_plist
|
|
||||||
|
|
||||||
plistlib.writePlist(entry_plist, filename)
|
plistlib.writePlist(entry_plist, filename)
|
||||||
|
|
Loading…
Add table
Reference in a new issue