Add tag to XML file when edited DayOne entry and is searchable afterward (#1648)

* Add tag to XML file when edited DayOne entry
* Remove forbidden change
* undo edits
* Tags working for DayOne journal
* Correction doentries to prevent time-error
* Add sorting to tags
* Delete test statements
* Revert time changes
This commit is contained in:
Jonathan van der Steege 2023-01-07 21:51:07 +01:00 committed by GitHub
parent 7229d77bda
commit 907566b39f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View file

@ -74,6 +74,7 @@ class DayOne(Journal.Journal):
self.config["tagsymbols"][0] + tag.lower()
for tag in dict_entry.get("Tags", [])
]
if entry._tags: entry._tags.sort()
"""Extended DayOne attributes"""
# just ignore it if the keys don't exist
@ -167,7 +168,7 @@ class DayOne(Journal.Journal):
return "\n".join([f"{str(e)}\n# {e.uuid}\n" for e in self.entries])
def _update_old_entry(self, entry: Entry, new_entry: Entry) -> None:
for attr in ("title", "body", "date"):
for attr in ("title", "body", "date", "tags"):
old_attr = getattr(entry, attr)
new_attr = getattr(new_entry, attr)
if old_attr != new_attr:
@ -195,6 +196,7 @@ class DayOne(Journal.Journal):
for entry in entries_from_editor:
entry = self._get_and_remove_uuid_from_entry(entry)
if entry._tags: entry._tags.sort()
# Remove deleted entries
edited_uuids = [e.uuid for e in entries_from_editor]
@ -204,5 +206,9 @@ class DayOne(Journal.Journal):
for entry in entries_from_editor:
for old_entry in self.entries:
if entry.uuid == old_entry.uuid:
if old_entry._tags:
tags_not_in_body = [tag for tag in old_entry._tags if(tag not in entry._body)]
if tags_not_in_body:
entry._tags.extend(tags_not_in_body.sort())
self._update_old_entry(old_entry, entry)
break

View file

@ -334,3 +334,20 @@ Feature: Writing new entries.
When we run "jrnl work This is a new entry"
Then the output should contain "Entry added to work journal"
And we should get no error
Scenario Outline: Tags are saved when an entry is edited with --edit and can be searched afterward
Given we use the config "<config_file>"
And we use the password "test" if prompted
And we append to the editor if opened
@newtag
When we run "jrnl --edit -1"
When we run "jrnl --tags @newtag"
Then the output should contain
1 entry found
Examples: configs
| config_file |
| basic_onefile.yaml |
| basic_encrypted.yaml |
| basic_folder.yaml |
| basic_dayone.yaml |