diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-04-11 23:06:36 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-04-11 23:06:36 +0200 |
commit | 94998dfb34ce7e659e1ed98c09fa62f31215cb2e (patch) | |
tree | 2ac36aeb8dab6bbbffc6d1dd82f678a80c7daa63 /talerbank/app/management | |
parent | d6b932db9b2de156baaa35abc5cc8ce4988acd03 (diff) | |
download | bank-94998dfb34ce7e659e1ed98c09fa62f31215cb2e.tar.gz bank-94998dfb34ce7e659e1ed98c09fa62f31215cb2e.tar.bz2 bank-94998dfb34ce7e659e1ed98c09fa62f31215cb2e.zip |
missing file
Diffstat (limited to 'talerbank/app/management')
-rw-r--r-- | talerbank/app/management/commands/provide_accounts.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/talerbank/app/management/commands/provide_accounts.py b/talerbank/app/management/commands/provide_accounts.py new file mode 100644 index 0000000..aa03a18 --- /dev/null +++ b/talerbank/app/management/commands/provide_accounts.py @@ -0,0 +1,79 @@ +""" + This file is part of TALER + (C) 2014, 2015, 2106 INRIA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> + + @author Marcello Stanisci + @author Florian Dold +""" + +import sys +import logging +from django.apps import AppConfig +from django.contrib.auth.models import User +from django.db.utils import ProgrammingError, DataError +from django.core.management.base import BaseCommand +from ...lib import get_currency +from ...models import BankAccount +from ...config import pre_accounts, expects_donations + +logger = logging.getLogger(__name__) + +def demo_accounts(): + for name in pre_accounts: + try: + User.objects.get(username=name) + except ProgrammingError as e: + logger.error("DB does not exist") + sys.exit(1) + except User.DoesNotExist: + try: + a = User.objects.create_user(username=name, password='') + except DataError: + logger.error("Given username exceeded 30 chars, please make it shorter!") + return + is_public = not (name == 'http://mint.test.taler.net' or + name == 'http://mint.demo.taler.net') + b = BankAccount(user=a, + currency=get_currency(None), + is_public=is_public) + b.save() + logger.info("getting account number " + str(b.account_no)) + + +def ensure_account(name): + try: + bank = User.objects.get(username=name) + except ProgrammingError: + logging.error("Please create DB before running the bank") + sys.exit(1) + except User.DoesNotExist: + user = User.objects.create_user(username=name, password='') + acc = BankAccount(user=user, + currency=get_currency(None), + is_public=True) + logger.info("Creating '" + name + "' account, with number " + str(acc.account_no)) + + +def basic_accounts(): + ensure_account("Bank") + ensure_account("Exchange") + + +class Command(BaseCommand): + help = "Provide initial user accounts" + + def handle(self, *args, **options): + basic_accounts() + demo_accounts() + |