espenmn
(Espen)
February 22, 2018, 8:54pm
1
I use:
members_groups = api.group.get_groups(user=member)
all_groups = ', '.join(str(e) for e in member_groups[0:])
( which shows something like 'Member of football, tennis', 'etc' in a browser view.pt
Is there a syntax for getting every group but not 'AuthenticatedUsers' (it is a Virtual Group'.)
(instead of searching for it and removing it ):
jaroel
(Roel Bruggink)
February 23, 2018, 10:20am
2
yeah, list.remove
:
>>> groups = ['AuthenticatedUsers','Monkey', 'Nut', 'Fire']
>>> groups.remove('AuthenticatedUsers')
>>> groups
['Monkey', 'Nut', 'Fire']
espenmn
(Espen)
February 23, 2018, 10:32am
3
Thanks…
I was a bit unsure if 'AuthenticatedUsers' could end up being translated somewhere, or if groups are:
groups = ['AuthenticatedUsers','Monkey', 'Nut', 'Fire']
or
groups = [< Some Groups Object>, < Some other object>]
EDIT the above line had disappeared.
zopyx
(Andreas Jung)
February 23, 2018, 10:55am
4
Makes no sense..the API does not exposed ids or whatever in a translated way...you should know this.
espenmn
(Espen)
February 23, 2018, 2:28pm
6
groups = api.group.get_groups(user=member) gives group=
[< GroupData at /xxx/portal_groupdata/AuthenticatedUsers used for /xxx/acl_users>,
<GroupData at /xxx/portal_groupdata/ABC used for /dgh/acl_users/source_groups>]
So, to remove it I need to convert it to string somehow ??
Something like this would work, but it looks very clumsy…
groups = api.group.get_groups(user=member)
grup = ' '.join(str(e) for e in groups).split()
grup.remove('AuthenticatedUsers')
group = ', '.join(str(e) for e in grup)
jaroel
(Roel Bruggink)
February 23, 2018, 7:19pm
7
Why are you joining the names and then splitting it again?
Just do this:
groups = api.group.get_groups(user=member)
groups = [e.getGroupName() for e in groups]
groups.remove('AuthenticatedUsers')
groups = ','.join(groups)
Unsure about the e.getGroupName()
stuff, though. It might be e.id
, or something like that.
espenmn
(Espen)
February 26, 2018, 3:36pm
8
because I did not think/know of doing it the e.getGroupName way… so I ended up with an 'id that changed'.
Thanks for your help
jaroel
(Roel Bruggink)
February 27, 2018, 8:33pm
9
Oh, not that, but the grup = ' '.join(str(e) for e in groups).split()
bit
grup = [str(e) for e in groups]
is the same