1313
1414
1515class _RelatedTagsBase (ContextManager , ABC ):
16- @property
17- @abstractmethod
18- def content_items (self ) -> _TagContentItemsBase :
19- pass
20-
2116 @abstractmethod
2217 def find (self ) -> list [Tag ]:
2318 pass
2419
2520
26- class _TagContentItemsBase (ContextManager , ABC ):
27- @staticmethod
28- def _unique_content_items (tags : list [Tag ]) -> list [ContentItem ]:
29- content_items : list [ContentItem ] = []
30- content_items_seen : set [str ] = set ()
31-
32- for tag in tags :
33- tag_content_items = tag .content_items .find ()
34-
35- for content_item in tag_content_items :
36- content_item_guid = content_item ["guid" ]
37-
38- if content_item_guid not in content_items_seen :
39- content_items .append (content_item )
40- content_items_seen .add (content_item_guid )
41-
42- return content_items
43-
44- @abstractmethod
45- def find (self ) -> list [ContentItem ]: ...
46-
47-
4821class Tag (Active ):
4922 """Tag resource."""
5023
@@ -163,7 +136,7 @@ def destroy(self) -> None:
163136 self ._ctx .session .delete (url )
164137
165138
166- class TagContentItems (_TagContentItemsBase ):
139+ class TagContentItems (ContextManager ):
167140 def __init__ (self , ctx : Context , path : str ) -> None :
168141 super ().__init__ ()
169142 self ._ctx = ctx
@@ -205,29 +178,6 @@ def __init__(self, ctx: Context, path: str, /, *, parent_tag: Tag) -> None:
205178
206179 self ._parent_tag = parent_tag
207180
208- @property
209- def content_items (self ) -> ChildTagContentItems :
210- """
211- Find all content items from the child tags.
212-
213- Returns
214- -------
215- ChildTagContentItems
216- Helper class that can `.find()` all content items that are tagged with a child tag.
217-
218- Examples
219- --------
220- ```python
221- import posit
222-
223- client = posit.connect.Client()
224- mytag = client.tags.get("TAG_ID_HERE")
225-
226- tagged_content_items = mytag.child_tags.content_items.find()
227- ```
228- """
229- return ChildTagContentItems (self ._ctx , self ._path , parent_tag = self ._parent_tag )
230-
231181 def find (self ) -> list [Tag ]:
232182 """
233183 Find all child tags that are direct children of a single tag.
@@ -252,101 +202,12 @@ def find(self) -> list[Tag]:
252202 return child_tags
253203
254204
255- class ChildTagContentItems (_TagContentItemsBase ):
256- def __init__ (self , ctx : Context , path : str , / , * , parent_tag : Tag ) -> None :
257- super ().__init__ ()
258- self ._ctx = ctx
259- self ._path = path
260- self ._parent_tag = parent_tag
261-
262- def find (self ) -> list [ContentItem ]:
263- """
264- Find all content items that are tagged with a child tag.
265-
266- Returns
267- -------
268- list[ContentItem]
269- List of content items that are tagged with a child tag.
270-
271- Examples
272- --------
273- ```python
274- import posit
275-
276- client = posit.connect.Client()
277- mytag = client.tags.get("TAG_ID_HERE")
278-
279- tagged_content_items = mytag.child_tags.content_items.find()
280- ```
281- """
282- child_tags = self ._parent_tag .child_tags .find ()
283- content_items = self ._unique_content_items (child_tags )
284- return content_items
285-
286-
287- class DescendantTagContentItems (_TagContentItemsBase ):
288- def __init__ (self , ctx : Context , / , * , parent_tag : Tag ) -> None :
289- super ().__init__ ()
290- self ._ctx = ctx
291- self ._parent_tag = parent_tag
292-
293- def find (self ) -> list [ContentItem ]:
294- """
295- Find all content items that are tagged with a descendant tag.
296-
297- Returns
298- -------
299- list[ContentItem]
300- List of content items that are tagged with a descendant tag.
301-
302- Examples
303- --------
304- ```python
305- import posit
306-
307- client = posit.connect.Client()
308- mytag = client.tags.get("TAG_ID_HERE")
309-
310- tagged_content_items = mytag.descendant_tags.content_items.find()
311- ```
312- """
313- descendant_tags = self ._parent_tag .descendant_tags .find ()
314- content_items = self ._unique_content_items (descendant_tags )
315- return content_items
316-
317-
318205class DescendantTags (_RelatedTagsBase ):
319206 def __init__ (self , ctx : Context , / , * , parent_tag : Tag ) -> None :
320207 super ().__init__ ()
321208 self ._ctx = ctx
322209 self ._parent_tag = parent_tag
323210
324- @property
325- def content_items (self ) -> DescendantTagContentItems :
326- """
327- Find all content items from the descendant tags.
328-
329- Returns
330- -------
331- DescendantTagContentItems
332- Helper class that can `.find()` all content items that are tagged with a descendant tag.
333-
334- Examples
335- --------
336- ```python
337- import posit
338-
339- client = posit.connect.Client()
340- mytag = client.tags.find(id="TAG_ID_HERE")
341-
342- tagged_content_items = mytag.descendant_tags.content_items.find()
343- ```
344- """
345- return DescendantTagContentItems (
346- self ._ctx ,
347- parent_tag = self ._parent_tag ,
348- )
349-
350211 def find (self ) -> list [Tag ]:
351212 """
352213 Find all child tags that descend from a single tag.
0 commit comments