From e4bc0794f13e01cbaa5cc5173d2ab3a097303cf5 Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Fri, 20 Dec 2013 16:16:35 +0100 Subject: [PATCH] Modified flag for entries --- jrnl/Entry.py | 1 + jrnl/Journal.py | 15 ++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/jrnl/Entry.py b/jrnl/Entry.py index 4948cc1d..a3c20b40 100644 --- a/jrnl/Entry.py +++ b/jrnl/Entry.py @@ -13,6 +13,7 @@ class Entry: self.body = body.strip() self.tags = self.parse_tags() self.starred = starred + self.modified = False def parse_tags(self): fulltext = " ".join([self.title, self.body]).lower() diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 906294bb..8a14d008 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -308,6 +308,7 @@ class Journal(object): if not date: # Still nothing? Meh, just live in the moment. date = self.parse_date("now") entry = Entry.Entry(self, date, title, body, starred=starred) + entry.modified = True self.entries.append(entry) if sort: self.sort() @@ -350,21 +351,17 @@ class DayOne(Journal): def write(self): """Writes only the entries that have been modified into plist files.""" for entry in self.entries: - # Assumption: since jrnl can not manipulate existing entries, all entries - # that have a uuid will be old ones, and only the one that doesn't will - # have a new one! - if not hasattr(entry, "uuid"): + if entry.modified: + if not hasattr(entry, "uuid"): + entry.uuid = uuid.uuid1().hex utc_time = datetime.utcfromtimestamp(time.mktime(entry.date.timetuple())) - new_uuid = uuid.uuid1().hex - filename = os.path.join(self.config['journal'], "entries", new_uuid+".doentry") + filename = os.path.join(self.config['journal'], "entries", entry.uuid+".doentry") entry_plist = { 'Creation Date': utc_time, 'Starred': entry.starred if hasattr(entry, 'starred') else False, 'Entry Text': entry.title+"\n"+entry.body, 'Time Zone': util.get_local_timezone(), - 'UUID': new_uuid, + 'UUID': entry.uuid, 'Tags': [tag.strip(self.config['tagsymbols']) for tag in entry.tags] } - # print entry_plist - plistlib.writePlist(entry_plist, filename)