From 9ff20740dda790ea933eb4b6159bd0265dad8d85 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 21 Jul 2023 17:21:08 +0200 Subject: [PATCH] get user from .env config --- ereuse_devicehub/commands/initdatas.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ereuse_devicehub/commands/initdatas.py b/ereuse_devicehub/commands/initdatas.py index 4e199fa4..11b60ceb 100644 --- a/ereuse_devicehub/commands/initdatas.py +++ b/ereuse_devicehub/commands/initdatas.py @@ -1,6 +1,7 @@ from uuid import uuid4 from boltons.urlutils import URL +from decouple import config from ereuse_devicehub.db import db from ereuse_devicehub.resources.agent.models import Person @@ -13,6 +14,9 @@ class InitDatas: super().__init__() self.app = app self.schema = app.config.get('DB_SCHEMA') + self.email = config('EMAIL_DEMO') + self.name = self.email.split('@')[0] if self.email else None + self.password = config('PASSWORD_DEMO') self.app.cli.command( 'initdata', short_help='Save a minimum structure of datas.' )(self.run) @@ -29,12 +33,9 @@ class InitDatas: db.session.add(inv) db.session.commit() - email = 'user@dhub.com' - password = '1234' - name = 'user' + if self.email: + user = User(email=self.email, password=self.password) + user.individuals.add(Person(name=self.name)) + db.session.add(user) - user = User(email=email, password=password) - user.individuals.add(Person(name=name)) - db.session.add(user) - - db.session.commit() + db.session.commit()