add command initial datas
This commit is contained in:
parent
9b42130e0c
commit
82a67fe3ab
0
idhub/management/__init__.py
Normal file
0
idhub/management/__init__.py
Normal file
0
idhub/management/commands/__init__.py
Normal file
0
idhub/management/commands/__init__.py
Normal file
39
idhub/management/commands/initial_datas.py
Normal file
39
idhub/management/commands/initial_datas.py
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from idhub.models import Organization
|
||||||
|
|
||||||
|
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Insert minimum datas for the project"
|
||||||
|
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
admin = 'admin@example.org'
|
||||||
|
pw_admin = '1234'
|
||||||
|
|
||||||
|
user = 'user1@example.org'
|
||||||
|
pw_user = '1234'
|
||||||
|
organization = [
|
||||||
|
("ExO", "https://verify.exo.cat"),
|
||||||
|
("Somos Connexión", "https://verify.somosconexion.coop")
|
||||||
|
]
|
||||||
|
|
||||||
|
# self.create_admin_users(admin, pw_admin)
|
||||||
|
self.create_users(user, pw_user)
|
||||||
|
for o in organization:
|
||||||
|
self.create_organizations(*o)
|
||||||
|
|
||||||
|
def create_admin_users(self, email, password):
|
||||||
|
User.objects.create_superuser(email=email, password=password)
|
||||||
|
|
||||||
|
|
||||||
|
def create_users(self, email, password):
|
||||||
|
u= User.objects.create(email=email, password=password)
|
||||||
|
u.set_password(password)
|
||||||
|
u.save()
|
||||||
|
|
||||||
|
|
||||||
|
def create_organizations(self, name, url):
|
||||||
|
Organization.objects.create(name=name, url=url)
|
|
@ -1,41 +0,0 @@
|
||||||
import os
|
|
||||||
import django
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'trustchain_idhub.settings') # noqa
|
|
||||||
django.setup() # noqa
|
|
||||||
|
|
||||||
from django.contrib.auth import get_user_model
|
|
||||||
from idhub.models import Organization
|
|
||||||
|
|
||||||
|
|
||||||
User = get_user_model()
|
|
||||||
|
|
||||||
|
|
||||||
def create_admin_users(email, password):
|
|
||||||
User.objects.create_superuser(email=email, password=password)
|
|
||||||
|
|
||||||
|
|
||||||
def create_users(email, password):
|
|
||||||
u= User.objects.create(email=email, password=password)
|
|
||||||
u.set_password(password)
|
|
||||||
u.save()
|
|
||||||
|
|
||||||
|
|
||||||
def create_organizations():
|
|
||||||
Organization.objects.create(name="ExO", url="https://verify.exo.cat")
|
|
||||||
Organization.objects.create(name="Somos Connexión", url="https://verify.somosconexion.coop")
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
admin = 'admin@example.org'
|
|
||||||
pw_admin = '1234'
|
|
||||||
|
|
||||||
user = 'user1@example.org'
|
|
||||||
pw_user = '1234'
|
|
||||||
|
|
||||||
# create_admin_users(admin, pw_admin)
|
|
||||||
create_users(user, pw_user)
|
|
||||||
create_organizations()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
Loading…
Reference in a new issue