diff --git a/docs/user/creolewiki.rst b/docs/user/creolewiki.rst index 8eb70acf9..881df3e68 100644 --- a/docs/user/creolewiki.rst +++ b/docs/user/creolewiki.rst @@ -429,6 +429,7 @@ The **ItemList** macro accepts multiple named parameters: item, startswith, rege - <> displays ordered list of subitems, default is unordered - <> lists subitems starting with Foo - <> lists subitems ending with Foo + - <> only include items with this tag - <> ignore items with this tag - <> default, displays full path to subitems - <> displays last component of the FullPath, including the '/' diff --git a/docs/user/moinwiki.rst b/docs/user/moinwiki.rst index 091fe9ca2..51bfaf5cd 100644 --- a/docs/user/moinwiki.rst +++ b/docs/user/moinwiki.rst @@ -882,6 +882,7 @@ The **ItemList** macro accepts multiple named parameters: item, startswith, rege - <> displays ordered list of subitems, default is unordered - <> lists subitems starting with Foo - <> lists subitems ending with Foo + - <> only include items with this tag - <> ignore items with this tag - <> default, displays full path to subitems - <> displays last component of the FullPath, including the '/' diff --git a/src/moin/macros/ItemList.py b/src/moin/macros/ItemList.py index 410133269..c09bd3ed1 100644 --- a/src/moin/macros/ItemList.py +++ b/src/moin/macros/ItemList.py @@ -29,6 +29,8 @@ skiptag: a tag name, items with tag will be skipped + tag: only include items that have been tagged with this name + display: How should the link be displayed? Options: @@ -79,6 +81,7 @@ def macro(self, content, arguments, page_url, alternative): ordered = False display = "FullPath" skiptag = "" + tag = "" # process input args = [] @@ -119,6 +122,8 @@ def macro(self, content, arguments, page_url, alternative): display = val # let 'create_pagelink_list' throw an exception if needed elif key == "skiptag": skiptag = val + elif key == "tag": + tag = val else: err_msg = _('Unrecognized key "{key}".').format(key=key) return fail_message(err_msg, alternative) @@ -136,7 +141,7 @@ def macro(self, content, arguments, page_url, alternative): return fail_message(err_msg, alternative) # process subitems - children = get_item_names(item, startswith=startswith, skiptag=skiptag) + children = get_item_names(item, startswith=startswith, skiptag=skiptag, tag=tag) if regex: try: regex_re = re.compile(regex, re.IGNORECASE) diff --git a/src/moin/macros/_base.py b/src/moin/macros/_base.py index 2eb3db5ad..ace3a9887 100644 --- a/src/moin/macros/_base.py +++ b/src/moin/macros/_base.py @@ -19,7 +19,7 @@ from moin.constants.keys import TAGS -def get_item_names(name="", startswith="", kind="files", skiptag=""): +def get_item_names(name="", startswith="", kind="files", skiptag="", tag=""): """ For the specified item, return the fullname of matching descendents. @@ -39,6 +39,8 @@ def get_item_names(name="", startswith="", kind="files", skiptag=""): skiptag: skip items having this tag + tag: only include items having this tag + Output: A List of descendent items using their "fullname" value @@ -53,11 +55,17 @@ def get_item_names(name="", startswith="", kind="files", skiptag=""): for item in files: if skiptag and TAGS in item.meta and skiptag in item.meta[TAGS]: continue + if tag: + if TAGS not in item.meta or tag not in item.meta[TAGS]: + continue item_names.append(item.fullname) if kind == "dirs" or kind == "both": for item in dirs: if skiptag and skiptag in item.meta[TAGS]: continue + if tag: + if TAGS not in item.meta or tag not in item.meta[TAGS]: + continue item_names.append(item.fullname) if kind == "both": item_names = list(set(item_names)) # remove duplicates