forked from benadida/helios-server
-
Notifications
You must be signed in to change notification settings - Fork 27
/
init_admin.py
40 lines (33 loc) · 1.04 KB
/
init_admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import sys
sys.path.insert(0, '.')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
# this initializes django checks
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
from zeus.models import *
from heliosauth.models import *
from heliosauth.auth_systems.password import make_password
from zeus.models import Institution
from django.conf import settings
def main(institution_name, username, password):
inst, created = Institution.objects.get_or_create(name=institution_name)
try:
user = User.objects.get(user_id=username)
except User.DoesNotExist:
user = User(user_id=username)
user.user_type = "password"
user.name = username
user.superadmin_p = True
user.management_p = True
user.institution = inst
user.ecounting_account = False
user.info = {
"name": username,
"password": make_password(password)
}
if not user.pk:
user.save()
user.user_groups = UserGroup.objects.all()
user.save()
main(*sys.argv[1:])