@@ -89,24 +89,23 @@ class UserGroup(BaseModel):
89
89
Represents a user group in Labelbox.
90
90
91
91
Attributes:
92
- id (Optional[ str] ): The ID of the user group.
93
- name (Optional[ str] ): The name of the user group.
92
+ id (str): The ID of the user group.
93
+ name (str): The name of the user group.
94
94
color (UserGroupColor): The color of the user group.
95
95
users (Set[UserGroupUser]): The set of users in the user group.
96
96
projects (Set[UserGroupProject]): The set of projects associated with the user group.
97
97
client (Client): The Labelbox client object.
98
98
99
99
Methods:
100
- __init__(self, client: Client, id: str = "", name: str = "", color: UserGroupColor = UserGroupColor.BLUE,
101
- users: Set[UserGroupUser] = set(), projects: Set[UserGroupProject] = set(), reload=True)
102
- _reload(self)
100
+ __init__(self, client: Client)
101
+ get(self) -> "UserGroup"
103
102
update(self) -> "UserGroup"
104
103
create(self) -> "UserGroup"
105
104
delete(self) -> bool
106
105
get_user_groups(client: Client) -> Iterator["UserGroup"]
107
106
"""
108
- id : Optional [ str ]
109
- name : Optional [ str ]
107
+ id : str
108
+ name : str
110
109
color : UserGroupColor
111
110
users : Set [UserGroupUser ]
112
111
projects : Set [UserGroupProject ]
@@ -119,51 +118,38 @@ class Config:
119
118
def __init__ (
120
119
self ,
121
120
client : Client ,
122
- id : str = "" ,
123
- name : str = "" ,
124
- color : UserGroupColor = UserGroupColor .BLUE ,
125
- users : Set [UserGroupUser ] = set (),
126
- projects : Set [UserGroupProject ] = set (),
127
- reload = True ,
128
121
):
129
122
"""
130
123
Initializes a UserGroup object.
131
124
132
125
Args:
133
126
client (Client): The Labelbox client object.
134
- id (str, optional): The ID of the user group. Defaults to an empty string.
135
- name (str, optional): The name of the user group. Defaults to an empty string.
136
- color (UserGroupColor, optional): The color of the user group. Defaults to UserGroupColor.BLUE.
137
- users (Set[UserGroupUser], optional): The set of users in the user group. Defaults to an empty set.
138
- projects (Set[UserGroupProject], optional): The set of projects associated with the user group. Defaults to an empty set.
139
- reload (bool, optional): Whether to reload the partial representation of the group. Defaults to True.
140
127
141
128
Raises:
142
129
RuntimeError: If the experimental feature is not enabled in the client.
143
130
144
131
"""
145
- super ().__init__ (client = client , id = id , name = name , color = color , users = users , projects = projects )
132
+ super ().__init__ (client = client , id = "" , name = "" , color = UserGroupColor . BLUE , users = set () , projects = set () )
146
133
if not self .client .enable_experimental :
147
134
raise RuntimeError (
148
135
"Please enable experimental in client to use UserGroups" )
149
136
150
- # partial representation of the group, reload
151
- if self .id and reload :
152
- self ._reload ()
153
-
154
- def _reload (self ):
137
+ def get (self ) -> "UserGroup" :
155
138
"""
156
139
Reloads the user group information from the server.
157
140
158
141
This method sends a GraphQL query to the server to fetch the latest information
159
142
about the user group, including its name, color, projects, and members. The fetched
160
143
information is then used to update the corresponding attributes of the `Group` object.
161
144
162
- Raises :
163
- InvalidQueryError: If the query fails to fetch the group information .
145
+ Args :
146
+ id (str): The ID of the user group to fetch.
164
147
165
148
Returns:
166
- None
149
+ UserGroup of passed in ID (self)
150
+
151
+ Raises:
152
+ InvalidQueryError: If the query fails to fetch the group information.
167
153
"""
168
154
query = """
169
155
query GetUserGroupPyApi($id: ID!) {
@@ -204,6 +190,7 @@ def _reload(self):
204
190
UserGroupUser (id = member ["id" ], email = member ["email" ])
205
191
for member in result ["userGroup" ]["members" ]["nodes" ]
206
192
}
193
+ return self
207
194
208
195
def update (self ) -> "UserGroup" :
209
196
"""
@@ -397,21 +384,19 @@ def get_user_groups(client: Client) -> Iterator["UserGroup"]:
397
384
yield
398
385
groups = userGroups ["nodes" ]
399
386
for group in groups :
400
- yield UserGroup (client ,
401
- reload = False ,
402
- id = group ["id" ],
403
- name = group ["name" ],
404
- color = UserGroupColor (group ["color" ]),
405
- users = {
406
- UserGroupUser (id = member ["id" ],
407
- email = member ["email" ])
408
- for member in group ["members" ]["nodes" ]
409
- },
410
- projects = {
411
- UserGroupProject (id = project ["id" ],
412
- name = project ["name" ])
413
- for project in group ["projects" ]["nodes" ]
414
- })
387
+ userGroup = UserGroup (client )
388
+ userGroup .id = group ["id" ]
389
+ userGroup .name = group ["name" ]
390
+ userGroup .color = UserGroupColor (group ["color" ])
391
+ userGroup .users = {
392
+ UserGroupUser (id = member ["id" ], email = member ["email" ])
393
+ for member in group ["members" ]["nodes" ]
394
+ }
395
+ userGroup .projects = {
396
+ UserGroupProject (id = project ["id" ], name = project ["name" ])
397
+ for project in group ["projects" ]["nodes" ]
398
+ }
399
+ yield userGroup
415
400
nextCursor = userGroups ["nextCursor" ]
416
401
# this doesn't seem to be implemented right now to return a value other than null from the api
417
402
if not nextCursor :
0 commit comments