cleanup(fastapi): simplify aurweb.routers.accounts.accounts_post

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-11-14 15:32:11 -08:00
parent cee7512e4d
commit f8ba2c5342
No known key found for this signature in database
GPG key ID: F7E46DED420788F3

View file

@ -662,7 +662,7 @@ async def accounts(request: Request):
account_type.TRUSTED_USER_AND_DEV}) account_type.TRUSTED_USER_AND_DEV})
async def accounts_post(request: Request, async def accounts_post(request: Request,
O: int = Form(default=0), # Offset O: int = Form(default=0), # Offset
SB: str = Form(default=str()), # Search By SB: str = Form(default=str()), # Sort By
U: str = Form(default=str()), # Username U: str = Form(default=str()), # Username
T: str = Form(default=str()), # Account Type T: str = Form(default=str()), # Account Type
S: bool = Form(default=False), # Suspended S: bool = Form(default=False), # Suspended
@ -705,23 +705,19 @@ async def accounts_post(request: Request,
# Populate this list with any additional statements to # Populate this list with any additional statements to
# be ANDed together. # be ANDed together.
statements = [] statements = [
if account_type_id is not None: v for k, v in [
statements.append(models.AccountType.ID == account_type_id) (account_type_id is not None, models.AccountType.ID == account_type_id),
if U: (bool(U), models.User.Username.like(f"%{U}%")),
statements.append(models.User.Username.like(f"%{U}%")) (bool(S), models.User.Suspended == S),
if S: (bool(E), models.User.Email.like(f"%{E}%")),
statements.append(models.User.Suspended == S) (bool(R), models.User.RealName.like(f"%{R}%")),
if E: (bool(I), models.User.IRCNick.like(f"%{I}%")),
statements.append(models.User.Email.like(f"%{E}%")) (bool(K), models.User.PGPKey.like(f"%{K}%")),
if R: ] if k
statements.append(models.User.RealName.like(f"%{R}%")) ]
if I:
statements.append(models.User.IRCNick.like(f"%{I}%"))
if K:
statements.append(models.User.PGPKey.like(f"%{K}%"))
# Filter the query by combining all statements added above into # Filter the query by coe-mbining all statements added above into
# an AND statement, unless there's just one statement, which # an AND statement, unless there's just one statement, which
# we pass on to filter() as args. # we pass on to filter() as args.
if statements: if statements: