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)
| 551 | |
| 552 | |
| 553 | def search_teams(params, searchstring, use_regex=False): |
| 554 | """Search teams. |
| 555 | |
| 556 | Args: |
| 557 | params: KeeperParams |
| 558 | searchstring: Search string (tokens or regex depending on use_regex) |
| 559 | use_regex: If True, treat as regex. If False (default), token-based search. |
| 560 | If searchstring is empty, returns all teams. |
| 561 | """ |
| 562 | search_results = [] |
| 563 | |
| 564 | if not searchstring: |
| 565 | # No search string - return all teams |
| 566 | match_func = lambda target: True |
| 567 | elif use_regex: |
| 568 | p = re.compile(searchstring.lower()) |
| 569 | match_func = lambda target: p.search(target) |
| 570 | else: |
| 571 | # Token-based search: all tokens must match |
| 572 | tokens = [t.lower() for t in searchstring.split() if t.strip()] |
| 573 | if not tokens: |
| 574 | # No valid tokens - return all teams |
| 575 | match_func = lambda target: True |
| 576 | else: |
| 577 | match_func = lambda target: all(token in target for token in tokens) |
| 578 | |
| 579 | for team_uid in params.team_cache: |
| 580 | team = get_team(params, team_uid) |
| 581 | |
| 582 | target = team.to_lowerstring() |
| 583 | |
| 584 | if match_func(target): |
| 585 | logging.debug('Search success') |
| 586 | search_results.append(team) |
| 587 | |
| 588 | return search_results |
| 589 | |
| 590 | |
| 591 | def prepare_record(params, record): |
nothing calls this directly
no test coverage detected