Auto Paging for Users in Groups#204
Conversation
| @@ -59,10 +73,6 @@ def remove_user(self, group_item, user_id): | |||
| self._remove_user(group_item, user_id) | |||
| try: | |||
| users = group_item.users | |||
There was a problem hiding this comment.
This is actually unnecessary because every call is a new Pager now, but we could return the list from add_user or we can just remove this from the call enitrely
graysonarts
left a comment
There was a problem hiding this comment.
Can you show me an example of usage?
|
Usage: # get a list of users for each group
mapping = {}
groups = TSC.Pager(server.groups)
for group in groups:
server.groups.populate_users(group)
mapping[group.name] = group.users
# get users for one group, loop and do something
server.groups.populate_users(group)
my_users = group.users
for u in my_users:
do_the_thing(my_user)
# add/delete
server.groups.populate_users(group)
start = set(group.users)
server.groups.add_user([u1, u2, u3[)
end = server.groups.user
print(str(end - start)) |
…responses. Still need to add a len menthod to pager
| @@ -57,28 +71,12 @@ def create(self, group_item): | |||
| @api(version="2.0") | |||
| def remove_user(self, group_item, user_id): | |||
| self._remove_user(group_item, user_id) | |||
There was a problem hiding this comment.
At this point it may not even be necessary to have the _remove_user function since we don't do anything special now
| # Adds 1 user to 1 group | ||
| @api(version="2.0") | ||
| def add_user(self, group_item, user_id): | ||
| new_user = self._add_user(group_item, user_id) |
|
@RussTheAerialist Here's a cleaned up rev -- I've been testing manually for a bit and seems to work the way I think it should. I'd like to check this in and get @cmtoomey and @ugamarkj to check it out. If they like it, I can generalize it (I've got an idea to refactor it with passing callables all the way down) to other sub-models, whichever feels easier to maintain. |
graysonarts
left a comment
There was a problem hiding this comment.
Small minor nitpick but otherwise good 🚀
tableauserverclient/server/pager.py
Outdated
| if hasattr(endpoint, 'get'): | ||
| # The simpliest case is to take an Endpoint and call its get | ||
| self._endpoint = endpoint.get | ||
| else: |
There was a problem hiding this comment.
Elif callable(...):
...
Else:
raise ...
(Sorry I'm on my phone, didn't bring a computer with me to California)
There was a problem hiding this comment.
Oh good call, a little cleaner!
Subsumes #147 because the git history got all weird.
I still need to make the tests work properly, but a manual test indicates this all works well.
/cc @cmtoomey who may want to try this out