Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add/test many tag, tags, and content item tags methods #346

Merged
merged 23 commits into from
Dec 6, 2024

Conversation

schloerke
Copy link
Collaborator

@schloerke schloerke commented Nov 26, 2024

Fixes #345

Grab bag of python recipes using this PR

from posit.connect import Client
from posit.connect.tags import Tag
from posit.connect.content import ContentItem

client = Client()

# Get all tags

## Return all tags
tags: list[Tag] = client.tags.find()
some_tag: Tag = tags[0]

## Return all tags with name and parent
commonnametags: list[Tag] = client.tags.find(name="tag_name")
sibling_tags: list[Tag] = client.tags.find(parent_id="parent_tag_guid")
sibling_tags: list[Tag] = client.tags.find(parent=some_tag)
unique_tag: Tag = client.tags.find(name="tag_name", parent=some_tag)[0]


# Create Tag
mytag: Tag = client.tags.create(name="tag_name")
mytag: Tag = client.tags.create(name="tag_name", parent_id="parent_tag_guid")
mytag: Tag = client.tags.create(name="tag_name", parent=some_tag)

# Remove Tag
mytag.destroy()


# Content Item

## Find content using tags
mycontentitems: list[ContentItem] = mytag.content_items.find()
some_contentitem: ContentItem = mycontentitems[0]

## Get content item's tags
tags: list[Tag] = some_contentitem.tags.find()

## Add tags to content item
some_contentitem.tags.add(mytag)
some_contentitem.tags.add(mytag["id"])

## Remove tags from content item
some_contentitem.tags.delete(mytag)
some_contentitem.tags.delete(mytag["id"])



# Family Tree

## Get parent tag
parent_tag: Tag | None = mytag.parent_tag

## Find all children tags
children_tags: list[Tag] = mytag.children_tags.find()

## Find all descendant tags
descendant_tags: list[Tag] = mytag.descendant_tags.find()

## Find all unique content items for a tag and its descendant tags
my_tag.content_items.find()

@schloerke schloerke self-assigned this Nov 26, 2024
Copy link

github-actions bot commented Nov 27, 2024

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
2060 1913 93% 0% 🟢

New Files

File Coverage Status
src/posit/connect/tags.py 96% 🟢
TOTAL 96% 🟢

Modified Files

File Coverage Status
src/posit/connect/client.py 99% 🟢
src/posit/connect/content.py 96% 🟢
src/posit/connect/permissions.py 96% 🟢
TOTAL 97% 🟢

updated for commit: d705d92 by action🐍

* main:
  feat: Add `Permissions.delete(*permissions)` method (#339)
  ci: Add in recent docker integration version (#347)
…to help create combinations of each parameter
@schloerke schloerke marked this pull request as ready for review December 3, 2024 20:19
@schloerke schloerke requested a review from tdstein as a code owner December 3, 2024 20:19
@schloerke schloerke requested a review from toph-allen December 3, 2024 20:19
Copy link
Collaborator

@toph-allen toph-allen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding comments from our discussion

src/posit/connect/tags.py Outdated Show resolved Hide resolved
src/posit/connect/tags.py Show resolved Hide resolved
src/posit/connect/tags.py Outdated Show resolved Hide resolved
src/posit/connect/tags.py Outdated Show resolved Hide resolved
src/posit/connect/tags.py Outdated Show resolved Hide resolved
src/posit/connect/tags.py Outdated Show resolved Hide resolved
src/posit/connect/tags.py Outdated Show resolved Hide resolved
src/posit/connect/tags.py Outdated Show resolved Hide resolved
src/posit/connect/tags.py Outdated Show resolved Hide resolved
src/posit/connect/tags.py Outdated Show resolved Hide resolved
@schloerke schloerke marked this pull request as draft December 5, 2024 18:34
@schloerke
Copy link
Collaborator Author

Through the course of testing, I have realized that

tagA.content_items.find() is returning the same results as what I thought tagA.descendant_tags.content_items.find() + tagA.content_items.find() was suppose to do.

If a child tag is added to a content item, then all ancestor tags are also automatically added

Therefore... tagA.content_items.find() returns all content items that contain tagA or any of its descendant tags.

Therefore... I'm gutting tagA.child_tags.content_items and tagA.descendant_tags.content_items

@schloerke schloerke marked this pull request as ready for review December 6, 2024 20:18
@schloerke schloerke requested a review from toph-allen December 6, 2024 20:18
Copy link
Collaborator

@toph-allen toph-allen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🪼

@schloerke schloerke merged commit cbf3634 into main Dec 6, 2024
35 checks passed
@schloerke schloerke deleted the schloerke/345-tags branch December 6, 2024 20:47
@tdstein tdstein mentioned this pull request Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tags - Create, delete, info, find content with tag, and view content item tags
2 participants