add initial datas from envs vars
This commit is contained in:
parent
d581ce0a19
commit
686cf182e4
|
@ -0,0 +1,2 @@
|
||||||
|
"ExO";"https://verify.exo.cat"
|
||||||
|
"Somos Connexión";"https://verify.somosconexion.coop"
|
|
|
@ -1,5 +1,10 @@
|
||||||
|
import os
|
||||||
|
import csv
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
from decouple import config
|
||||||
from idhub.models import Organization
|
from idhub.models import Organization
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,20 +15,20 @@ class Command(BaseCommand):
|
||||||
help = "Insert minimum datas for the project"
|
help = "Insert minimum datas for the project"
|
||||||
|
|
||||||
def handle(self, *args, **kwargs):
|
def handle(self, *args, **kwargs):
|
||||||
admin = 'admin@example.org'
|
ADMIN_EMAIL = config('ADMIN_EMAIL', 'admin@example.org')
|
||||||
pw_admin = '1234'
|
ADMIN_PASSWORD = config('ADMIN_PASSWORD', '1234')
|
||||||
|
USER_EMAIL = config('USER_EMAIL', 'user1@example.org')
|
||||||
|
USER_PASSWORD = config('USER_PASSWORD', '1234')
|
||||||
|
|
||||||
user = 'user1@example.org'
|
self.create_admin_users(ADMIN_EMAIL, ADMIN_PASSWORD)
|
||||||
pw_user = '1234'
|
self.create_users(USER_EMAIL, USER_PASSWORD)
|
||||||
organization = [
|
|
||||||
("ExO", "https://verify.exo.cat"),
|
|
||||||
("Somos Connexión", "https://verify.somosconexion.coop")
|
|
||||||
]
|
|
||||||
|
|
||||||
# self.create_admin_users(admin, pw_admin)
|
BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent
|
||||||
self.create_users(user, pw_user)
|
ORGANIZATION = os.path.join(BASE_DIR, 'examples/organizations.csv')
|
||||||
for o in organization:
|
with open(ORGANIZATION, newline='\n') as csvfile:
|
||||||
self.create_organizations(*o)
|
f = csv.reader(csvfile, delimiter=';', quotechar='"')
|
||||||
|
for r in f:
|
||||||
|
self.create_organizations(r[0].strip(), r[1].strip())
|
||||||
|
|
||||||
def create_admin_users(self, email, password):
|
def create_admin_users(self, email, password):
|
||||||
User.objects.create_superuser(email=email, password=password)
|
User.objects.create_superuser(email=email, password=password)
|
||||||
|
|
Loading…
Reference in New Issue