gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-bank] branch master updated: be nice with small scre


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: be nice with small screens; add Survey account; make account generating logic shorter.
Date: Fri, 15 Dec 2017 11:39:33 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository bank.

The following commit(s) were added to refs/heads/master by this push:
     new a58a34b  be nice with small screens; add Survey account; make account 
generating logic shorter.
a58a34b is described below

commit a58a34bc37407e0302948978193fd51e465aeeb2
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Dec 15 11:38:47 2017 +0100

    be nice with small screens; add Survey account;
    make account generating logic shorter.
---
 talerbank/app/management/commands/helpers.py       | 24 ------
 .../app/management/commands/provide_accounts.py    | 48 +++++-------
 talerbank/settings.py                              | 89 ++++++++++++----------
 3 files changed, 64 insertions(+), 97 deletions(-)

diff --git a/talerbank/app/management/commands/helpers.py 
b/talerbank/app/management/commands/helpers.py
deleted file mode 100644
index 62137e9..0000000
--- a/talerbank/app/management/commands/helpers.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#  This file is part of TALER
-#  (C) 2017 Taler Systems SA
-#
-#  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, see <http://www.gnu.org/licenses/>
-#
-#  @author Marcello Stanisci
-
-import logging
-LOGGER = logging.getLogger(__name__)
-
-def hard_db_error_log():
-    LOGGER.error("likely causes: non existent DB or unmigrated project\n"
-                 "(try 'taler-bank-manage django migrate' in the latter case)",
-                 stack_info=False,
-                 exc_info=True)
diff --git a/talerbank/app/management/commands/provide_accounts.py 
b/talerbank/app/management/commands/provide_accounts.py
index c719296..cf8d6e9 100644
--- a/talerbank/app/management/commands/provide_accounts.py
+++ b/talerbank/app/management/commands/provide_accounts.py
@@ -22,42 +22,28 @@ from django.db.utils import ProgrammingError, 
OperationalError
 from django.core.management.base import BaseCommand
 from django.conf import settings
 from ...models import BankAccount
-from .helpers import hard_db_error_log
 
 LOGGER = logging.getLogger(__name__)
+LOGGER.setLevel(logging.INFO)
 
 
-def demo_accounts():
-    for name in settings.TALER_PREDEFINED_ACCOUNTS:
-        try:
-            User.objects.get(username=name)
-        except User.DoesNotExist:
-            BankAccount(user=User.objects.create_user(username=name, 
password='x'),
-                        is_public=True).save()
-            LOGGER.info("Creating account for '%s'", name)
-
-
-def ensure_account(name):
-    LOGGER.info("ensuring account '%s'", name)
-    user = None
+def make_account(username):
     try:
-        user = User.objects.get(username=name)
-    except (OperationalError, ProgrammingError):
-        hard_db_error_log()
-        sys.exit(1)
+        User.objects.get(username=username)
     except User.DoesNotExist:
-        LOGGER.info("Creating *user* account '%s'", name)
-        user = User.objects.create_user(username=name, password='x')
-
-    try:
-        BankAccount.objects.get(user=user)
-
-    except BankAccount.DoesNotExist:
-        acc = BankAccount(user=user, is_public=True)
-        acc.save()
-        LOGGER.info("Creating *bank* account number \
-                    '%s' for user '%s'", acc.account_no, name)
+        LOGGER.info("Creating account for '%s'", username)
+        BankAccount(
+            user=User.objects.create_user(
+                username=username, password='x'),
+            is_public=True).save()
 
+    except (OperationalError, ProgrammingError):
+        LOGGER.error("db does not exist, or the project"
+                     " is not migrated.  Try 'taler-bank-manage"
+                     " django migrate' in the latter case.",
+                     stack_info=False,
+                     exc_info=True)
+        sys.exit(1)
 
 def basic_accounts():
     ensure_account("Bank")
@@ -68,5 +54,5 @@ class Command(BaseCommand):
     help = "Provide initial user accounts"
 
     def handle(self, *args, **options):
-        basic_accounts()
-        demo_accounts()
+        for username in settings.TALER_PREDEFINED_ACCOUNTS:
+            make_account(username)
diff --git a/talerbank/settings.py b/talerbank/settings.py
index 6380937..bf16326 100644
--- a/talerbank/settings.py
+++ b/talerbank/settings.py
@@ -18,12 +18,15 @@ from .talerconfig import TalerConfig, ConfigurationError
 
 LOGGER = logging.getLogger(__name__)
 
-LOGGER.info("DJANGO_SETTINGS_MODULE: %s" % 
os.environ.get("DJANGO_SETTINGS_MODULE"))
+LOGGER.info("DJANGO_SETTINGS_MODULE: %s" \
+            % os.environ.get("DJANGO_SETTINGS_MODULE"))
 
 TC = TalerConfig.from_file(os.environ.get("TALER_CONFIG_FILE"))
 
-# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
-BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+# Build paths inside the project like this:
+# os.path.join(BASE_DIR, ...)
+BASE_DIR = os.path.dirname(
+    os.path.dirname(os.path.abspath(__file__)))
 
 # Quick-start development settings - unsuitable for production
 # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
@@ -32,8 +35,9 @@ BASE_DIR = 
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 SECRET_KEY = os.environ.get("TALER_BANK_SECRET_KEY", None)
 
 if not SECRET_KEY:
-    logging.info("secret key not configured in TALER_BANK_SECRET_KEY " \
-                 + "env variable, generating random secret")
+    LOGGER.info("secret key not configured in"
+                " TALER_BANK_SECRET_KEY env variable,"
+                " generating random secret")
     SECRET_KEY = base64.b64encode(os.urandom(32)).decode('utf-8')
 
 # SECURITY WARNING: don't run with debug turned on in production!
@@ -70,15 +74,13 @@ MIDDLEWARE = [
 ]
 
 TEMPLATES = [
-    {
-        'BACKEND': 'django.template.backends.jinja2.Jinja2',
-        'DIRS': [os.path.join(BASE_DIR, "talerbank/app/static/web-common/"),
-                 os.path.join(BASE_DIR, "talerbank/app/templates")],
-        'OPTIONS': {
-            'environment': 'talerbank.jinja2.environment',
-            },
-    },
-]
+    {'BACKEND': 'django.template.backends.jinja2.Jinja2',
+     'DIRS': [os.path.join(BASE_DIR,
+                           "talerbank/app/static/web-common/"),
+              os.path.join(BASE_DIR,
+                           "talerbank/app/templates")],
+     'OPTIONS': {
+         'environment': 'talerbank.jinja2.environment'}}]
 
 # Disable those, since they don't work with
 # jinja2 anyways.
@@ -96,13 +98,15 @@ DBNAME = TC.value_string("bank", "database", required=True)
 DBNAME = os.environ.get("TALER_BANK_ALTDB", DBNAME)
 
 if not DBNAME:
-    raise Exception("DB not specified (neither in config or as cli argument)")
+    raise Exception("DB not specified (neither in config or as" \
+                    "cli argument)")
 
 LOGGER.info("dbname: %s" % DBNAME)
 
 CHECK_DBSTRING_FORMAT = re.search("[a-z]+:///[a-z]+", DBNAME)
 if not CHECK_DBSTRING_FORMAT:
-    LOGGER.error("Bad db string given, respect the format 'dbtype:///dbname'")
+    LOGGER.error("Bad db string given, respect the format" \
+                 "'dbtype:///dbname'")
     sys.exit(2)
 
 DBCONFIG = {}
@@ -133,19 +137,14 @@ DATABASES["default"] = DBCONFIG
 # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
 
 AUTH_PASSWORD_VALIDATORS = [
-    {
-        'NAME': 
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
-    },
-    {
-        'NAME': 
'django.contrib.auth.password_validation.MinimumLengthValidator',
-    },
-    {
-        'NAME': 
'django.contrib.auth.password_validation.CommonPasswordValidator',
-    },
-    {
-        'NAME': 
'django.contrib.auth.password_validation.NumericPasswordValidator',
-    },
-]
+    {'NAME': 'django.contrib.auth.password_validation' \
+             '.UserAttributeSimilarityValidator'},
+    {'NAME': 'django.contrib.auth.password_validation' \
+             '.MinimumLengthValidator'},
+    {'NAME': 'django.contrib.auth.password_validation' \
+             '.CommonPasswordValidator'},
+    {'NAME': 'django.contrib.auth.password_validation' \
+             '.NumericPasswordValidator'}]
 
 
 # Internationalization
@@ -172,24 +171,30 @@ STATICFILES_DIRS = [
     os.path.join(BASE_DIR, "talerbank/app/static/web-common"),
 ]
 
-# Currently we don't use "collectstatic", so this value isn't used.
-# Instead, we serve static files directly from the installed python package
-# via the "django.contrib.staticfiles" app.
-# We must set it to something valid though, # or django will give us warnings.
 STATIC_ROOT = '/tmp/talerbankstatic/'
-
 ROOT_URLCONF = "talerbank.app.urls"
 
 try:
-    TALER_CURRENCY = TC.value_string("taler", "currency", required=True)
+    TALER_CURRENCY = TC.value_string(
+        "taler", "currency", required=True)
 except ConfigurationError as exc:
     LOGGER.error(exc)
     sys.exit(3)
 
-TALER_MAX_DEBT = TC.value_string("bank", "MAX_DEBT", default="%s:50.0" % 
TALER_CURRENCY)
-TALER_MAX_DEBT_BANK = TC.value_string("bank", "MAX_DEBT_BANK", 
default="%s:0.0" % TALER_CURRENCY)
-
-TALER_DIGITS = TC.value_int("bank", "NDIGITS", default=2)
-TALER_PREDEFINED_ACCOUNTS = ['Tor', 'GNUnet', 'Taler', 'FSF', 'Tutorial']
-TALER_EXPECTS_DONATIONS = ['Tor', 'GNUnet', 'Taler', 'FSF']
-TALER_SUGGESTED_EXCHANGE = TC.value_string("bank", "suggested_exchange")
+TALER_MAX_DEBT = TC.value_string(
+    "bank", "MAX_DEBT",
+    default="%s:50.0" % TALER_CURRENCY)
+TALER_MAX_DEBT_BANK = TC.value_string(
+    "bank", "MAX_DEBT_BANK",
+    default="%s:0.0" % TALER_CURRENCY)
+
+TALER_DIGITS = TC.value_int(
+    "bank", "NDIGITS", default=2)
+# Order matters
+TALER_PREDEFINED_ACCOUNTS = [
+    'Bank', 'Exchange', 'Tor', 'GNUnet',
+    'Taler', 'FSF', 'Tutorial', 'Survey']
+TALER_EXPECTS_DONATIONS = [
+    'Tor', 'GNUnet', 'Taler', 'FSF']
+TALER_SUGGESTED_EXCHANGE = TC.value_string(
+    "bank", "suggested_exchange")

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]