File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -324,6 +324,40 @@ def get_users(self, start_uid=0):
324324 else :
325325 break
326326
327+ def find_users (self , search_attrs , start_uid = 0 ):
328+ """ get user data records that match a given set of attributes
329+
330+ Obtain all user profiles that have all attributes (exact keys and values) in `search_attrs`.
331+
332+ Args:
333+ search_attrs (dict): one or multiple attributes that the user records need to match
334+ start_uid (int): (optional) the lowest user profile id to fetch (fetches next higher one if the given is does not exist)
335+
336+ Returns:
337+ A generator that yields user records, one at a time.
338+ """
339+ for user in self .get_users (start_uid ):
340+ matched = True
341+ for attr in search_attrs :
342+ if user [attr ] != search_attrs [attr ]:
343+ matched = False
344+ if matched :
345+ yield user
346+
347+ def find_user (self , search_attrs , start_uid = 0 ):
348+ """ get the first user data record that matches a given set of attributes
349+
350+ Obtains the first user profiles that has all attributes (exact keys and values) in `search_attrs`.
351+
352+ Args:
353+ search_attrs (dict): one or multiple attributes that the user record needs to match
354+ start_uid (int): (optional) the lowest user profile id to fetch (fetches next higher one if the given is does not exist)
355+
356+ Returns:
357+ A user record (dict) if a match was found, None otherwise.
358+ """
359+ return next (self .find_users (search_attrs , start_uid ), None )
360+
327361 def get_user (self , uid ):
328362 """ get user configuration data
329363
You can’t perform that action at this time.
0 commit comments