Search teams. Args: params: KeeperParams searchstring: Search string (tokens or regex depending on use_regex) use_regex: If True, treat as regex. If False (default), token-based search. If searchstring is empty, returns all teams.
(params, searchstring, use_regex=False)
| 587 | |
| 588 | |
| 589 | def search_teams(params, searchstring, use_regex=False): |
| 590 | """Search teams. |
| 591 | |
| 592 | Args: |
| 593 | params: KeeperParams |
| 594 | searchstring: Search string (tokens or regex depending on use_regex) |
| 595 | use_regex: If True, treat as regex. If False (default), token-based search. |
| 596 | If searchstring is empty, returns all teams. |
| 597 | """ |
| 598 | search_results = [] |
| 599 | |
| 600 | if not searchstring: |
| 601 | # No search string - return all teams |
| 602 | match_func = lambda target: True |
| 603 | elif use_regex: |
| 604 | p = re.compile(searchstring.lower()) |
| 605 | match_func = lambda target: p.search(target) |
| 606 | else: |
| 607 | # Token-based search: all tokens must match |
| 608 | tokens = [t.lower() for t in searchstring.split() if t.strip()] |
| 609 | if not tokens: |
| 610 | # No valid tokens - return all teams |
| 611 | match_func = lambda target: True |
| 612 | else: |
| 613 | match_func = lambda target: all(token in target for token in tokens) |
| 614 | |
| 615 | for team_uid in params.team_cache: |
| 616 | team = get_team(params, team_uid) |
| 617 | |
| 618 | target = team.to_lowerstring() |
| 619 | |
| 620 | if match_func(target): |
| 621 | logging.debug('Search success') |
| 622 | search_results.append(team) |
| 623 | |
| 624 | return search_results |
| 625 | |
| 626 | |
| 627 | def prepare_record(params, record): |
nothing calls this directly
no test coverage detected