def accounts(freezer): freezer.move_to('2012-02-01 12:00') expires_on = [ datetime.today() + timedelta(days=89), ] return [ Account(name='john', is_active=True, expires_on=expires_on[0]), Account(name='paul', is_active=False), ]
class AccountsManager: @staticmethod def exists(account_name): try: Account.get(Account.name == account_name) return True except DoesNotExist: return False @staticmethod @catcher('Getting account') def get_account(account_name) -> Account: return Account.get(Account.name == account_name) @staticmethod @catcher('Add') def add(account_name, password=None): if AccountsManager.exists(account_name): print_error(f'Cannot add {account_name} - account exists in DB.') return if not (password := password): password = Prompt.ask(f'{account_name} password', password=True) Account.create(name=account_name, password=password) print_success(f'Account {account_name} added.')
def get_all_accounts(): return Account.select()
def delete(account_name): deleted = Account.delete().where(Account.name == account_name).execute() if deleted: print_success(f'Account {account_name} deleted') else: print_warning(f'Delete failed - account {account_name} not found.')
def get_account(account_name) -> Account: return Account.get(Account.name == account_name)
def exists(account_name): try: Account.get(Account.name == account_name) return True except DoesNotExist: return False
def get_active_accounts(): return Account.select().where(Account.is_active)