Compare commits
No commits in common. "5019b44dd50f080ff499f8c74c6bef5bc6d537d8" and "bfe60271eb773ce4f1897918c7875fe8140003e0" have entirely different histories.
5019b44dd5
...
bfe60271eb
@ -752,20 +752,11 @@ class Headline:
|
|||||||
return times
|
return times
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tags(self) -> list[str]:
|
def tags(self):
|
||||||
parent_tags = self.parent.tags
|
if isinstance(self.parent, OrgDoc):
|
||||||
if self.doc.environment.get("org-use-tag-inheritance"):
|
return list(self.shallow_tags)
|
||||||
accepted_tags = []
|
else:
|
||||||
for tag in self.doc.environment.get("org-use-tag-inheritance"):
|
return list(self.shallow_tags) + self.parent.tags
|
||||||
if tag in parent_tags:
|
|
||||||
accepted_tags.append(tag)
|
|
||||||
parent_tags = accepted_tags
|
|
||||||
|
|
||||||
elif self.doc.environment.get("org-tags-exclude-from-inheritance"):
|
|
||||||
for tag in self.doc.environment.get("org-tags-exclude-from-inheritance"):
|
|
||||||
if tag in parent_tags:
|
|
||||||
parent_tags.remove(tag)
|
|
||||||
return list(self.shallow_tags) + parent_tags
|
|
||||||
|
|
||||||
def add_tag(self, tag: str):
|
def add_tag(self, tag: str):
|
||||||
self.shallow_tags.append(tag)
|
self.shallow_tags.append(tag)
|
||||||
@ -2246,7 +2237,6 @@ class OrgDoc:
|
|||||||
):
|
):
|
||||||
self.todo_keywords = [HeadlineState(name=kw) for kw in DEFAULT_TODO_KEYWORDS]
|
self.todo_keywords = [HeadlineState(name=kw) for kw in DEFAULT_TODO_KEYWORDS]
|
||||||
self.done_keywords = [HeadlineState(name=kw) for kw in DEFAULT_DONE_KEYWORDS]
|
self.done_keywords = [HeadlineState(name=kw) for kw in DEFAULT_DONE_KEYWORDS]
|
||||||
self.environment = environment
|
|
||||||
|
|
||||||
keywords_set_in_file = False
|
keywords_set_in_file = False
|
||||||
for keyword in keywords:
|
for keyword in keywords:
|
||||||
@ -2290,17 +2280,6 @@ class OrgDoc:
|
|||||||
def path(self):
|
def path(self):
|
||||||
return self._path
|
return self._path
|
||||||
|
|
||||||
@property
|
|
||||||
def tags(self) -> list[str]:
|
|
||||||
for kw in self.keywords:
|
|
||||||
if kw.key == "FILETAGS":
|
|
||||||
return kw.value.strip(":").split(":")
|
|
||||||
return []
|
|
||||||
|
|
||||||
@property
|
|
||||||
def shallow_tags(self) -> list[str]:
|
|
||||||
return self.tags
|
|
||||||
|
|
||||||
## Querying
|
## Querying
|
||||||
def get_links(self):
|
def get_links(self):
|
||||||
for headline in self.headlines:
|
for headline in self.headlines:
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
#+TITLE: 13-Tags
|
|
||||||
#+DESCRIPTION: Simple org file to test tags
|
|
||||||
#+FILETAGS: :filetag:
|
|
||||||
|
|
||||||
* Level 1 :h1tag:
|
|
||||||
:PROPERTIES:
|
|
||||||
:ID: 13-tags
|
|
||||||
:CREATED: [2020-01-01 Wed 01:01]
|
|
||||||
:END:
|
|
||||||
|
|
||||||
** Level2 :h2tag:
|
|
||||||
* Level 1-1 :otherh1tag:
|
|
||||||
** Level2 :otherh2tag:
|
|
@ -865,92 +865,6 @@ class TestSerde(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(dumps(doc), orig)
|
self.assertEqual(dumps(doc), orig)
|
||||||
|
|
||||||
def test_mimic_write_file_13(self):
|
|
||||||
with open(os.path.join(DIR, "13-tags.org")) as f:
|
|
||||||
orig = f.read()
|
|
||||||
doc = loads(orig)
|
|
||||||
|
|
||||||
self.assertEqual(dumps(doc), orig)
|
|
||||||
|
|
||||||
def test_tag_property_read_13(self):
|
|
||||||
with open(os.path.join(DIR, "13-tags.org")) as f:
|
|
||||||
orig = f.read()
|
|
||||||
doc = loads(orig)
|
|
||||||
|
|
||||||
self.assertEqual(doc.tags, ["filetag"])
|
|
||||||
|
|
||||||
h1_1, h1_2 = doc.getTopHeadlines()
|
|
||||||
self.assertEqual(sorted(h1_1.tags), ["filetag", "h1tag"])
|
|
||||||
self.assertEqual(sorted(h1_2.tags), ["filetag", "otherh1tag"])
|
|
||||||
|
|
||||||
h1_1_h2 = h1_1.children[0]
|
|
||||||
self.assertEqual(sorted(h1_1_h2.tags), ["filetag", "h1tag", "h2tag"])
|
|
||||||
|
|
||||||
h1_2_h2 = h1_2.children[0]
|
|
||||||
self.assertEqual(sorted(h1_2_h2.tags), ["filetag", "otherh1tag", "otherh2tag"])
|
|
||||||
|
|
||||||
def test_shallow_tag_property_read_13(self):
|
|
||||||
with open(os.path.join(DIR, "13-tags.org")) as f:
|
|
||||||
orig = f.read()
|
|
||||||
doc = loads(orig)
|
|
||||||
|
|
||||||
self.assertEqual(doc.shallow_tags, ["filetag"])
|
|
||||||
|
|
||||||
h1_1, h1_2 = doc.getTopHeadlines()
|
|
||||||
self.assertEqual(sorted(h1_1.shallow_tags), ["h1tag"])
|
|
||||||
self.assertEqual(sorted(h1_2.shallow_tags), ["otherh1tag"])
|
|
||||||
|
|
||||||
h1_1_h2 = h1_1.children[0]
|
|
||||||
self.assertEqual(sorted(h1_1_h2.shallow_tags), ["h2tag"])
|
|
||||||
|
|
||||||
h1_2_h2 = h1_2.children[0]
|
|
||||||
self.assertEqual(sorted(h1_2_h2.shallow_tags), ["otherh2tag"])
|
|
||||||
|
|
||||||
def test_exclude_tags_from_inheritance_property_read_13(self):
|
|
||||||
with open(os.path.join(DIR, "13-tags.org")) as f:
|
|
||||||
orig = f.read()
|
|
||||||
doc = loads(
|
|
||||||
orig,
|
|
||||||
{
|
|
||||||
"org-tags-exclude-from-inheritance": ("h1tag", "otherh2tag"),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(doc.tags, ["filetag"])
|
|
||||||
|
|
||||||
h1_1, h1_2 = doc.getTopHeadlines()
|
|
||||||
self.assertEqual(sorted(h1_1.tags), ["filetag", "h1tag"])
|
|
||||||
self.assertEqual(sorted(h1_2.tags), ["filetag", "otherh1tag"])
|
|
||||||
|
|
||||||
h1_1_h2 = h1_1.children[0]
|
|
||||||
self.assertEqual(sorted(h1_1_h2.tags), ["filetag", "h2tag"])
|
|
||||||
|
|
||||||
h1_2_h2 = h1_2.children[0]
|
|
||||||
self.assertEqual(sorted(h1_2_h2.tags), ["filetag", "otherh1tag", "otherh2tag"])
|
|
||||||
|
|
||||||
def test_select_tags_to_inheritance_property_read_13(self):
|
|
||||||
with open(os.path.join(DIR, "13-tags.org")) as f:
|
|
||||||
orig = f.read()
|
|
||||||
doc = loads(
|
|
||||||
orig,
|
|
||||||
{
|
|
||||||
"org-tags-exclude-from-inheritance": ("h1tag", "otherh2tag"),
|
|
||||||
"org-use-tag-inheritance": ("h1tag",),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(doc.tags, ["filetag"])
|
|
||||||
|
|
||||||
h1_1, h1_2 = doc.getTopHeadlines()
|
|
||||||
self.assertEqual(sorted(h1_1.tags), ["h1tag"])
|
|
||||||
self.assertEqual(sorted(h1_2.tags), ["otherh1tag"])
|
|
||||||
|
|
||||||
h1_1_h2 = h1_1.children[0]
|
|
||||||
self.assertEqual(sorted(h1_1_h2.tags), ["h1tag", "h2tag"])
|
|
||||||
|
|
||||||
h1_2_h2 = h1_2.children[0]
|
|
||||||
self.assertEqual(sorted(h1_2_h2.tags), ["otherh2tag"])
|
|
||||||
|
|
||||||
|
|
||||||
def print_tree(tree, indentation=0, headline=None):
|
def print_tree(tree, indentation=0, headline=None):
|
||||||
for element in tree:
|
for element in tree:
|
||||||
|
Loading…
Reference in New Issue
Block a user