This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2023-06-15 14:41:47 +00:00
|
|
|
from uuid import uuid4
|
|
|
|
|
|
|
|
from boltons.urlutils import URL
|
2023-07-21 15:21:08 +00:00
|
|
|
from decouple import config
|
2023-06-15 14:41:47 +00:00
|
|
|
|
|
|
|
from ereuse_devicehub.db import db
|
|
|
|
from ereuse_devicehub.resources.agent.models import Person
|
|
|
|
from ereuse_devicehub.resources.inventory.model import Inventory
|
|
|
|
from ereuse_devicehub.resources.user.models import User
|
|
|
|
|
|
|
|
|
|
|
|
class InitDatas:
|
|
|
|
def __init__(self, app) -> None:
|
|
|
|
super().__init__()
|
|
|
|
self.app = app
|
|
|
|
self.schema = app.config.get('DB_SCHEMA')
|
2023-07-21 15:21:08 +00:00
|
|
|
self.email = config('EMAIL_DEMO')
|
|
|
|
self.name = self.email.split('@')[0] if self.email else None
|
|
|
|
self.password = config('PASSWORD_DEMO')
|
2023-06-15 14:41:47 +00:00
|
|
|
self.app.cli.command(
|
|
|
|
'initdata', short_help='Save a minimum structure of datas.'
|
|
|
|
)(self.run)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
inv = Inventory(
|
|
|
|
id=self.schema,
|
|
|
|
name="usody",
|
|
|
|
tag_provider=URL('http://localhost:8081'),
|
|
|
|
tag_token=uuid4(),
|
|
|
|
org_id=uuid4(),
|
|
|
|
)
|
|
|
|
|
|
|
|
db.session.add(inv)
|
|
|
|
db.session.commit()
|
|
|
|
|
2024-02-16 09:51:56 +00:00
|
|
|
if self.email:
|
|
|
|
user = User(email=self.email, password=self.password)
|
|
|
|
user.individuals.add(Person(name=self.name))
|
|
|
|
db.session.add(user)
|
2023-06-15 14:41:47 +00:00
|
|
|
|
2024-02-16 09:51:56 +00:00
|
|
|
db.session.commit()
|