Пример #1
0
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),
    ]
Пример #2
0
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.')
Пример #3
0
 def get_all_accounts():
     return Account.select()
Пример #4
0
 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.')
Пример #5
0
 def get_account(account_name) -> Account:
     return Account.get(Account.name == account_name)
Пример #6
0
 def exists(account_name):
     try:
         Account.get(Account.name == account_name)
         return True
     except DoesNotExist:
         return False
Пример #7
0
 def get_active_accounts():
     return Account.select().where(Account.is_active)