-
Notifications
You must be signed in to change notification settings - Fork 6
/
create_admin.py
52 lines (41 loc) · 1.53 KB
/
create_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
41
42
43
44
45
46
47
48
49
50
51
52
import django
import os
import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "audiencias_publicas.settings")
def create_superuser():
from django.contrib.auth import get_user_model
User = get_user_model()
admin_email = os.environ.get('ADMIN_EMAIL', None)
admin_username = os.environ.get('ADMIN_USERNAME', None)
admin_passwd = os.environ.get('ADMIN_PASSWORD', None)
if None not in [admin_email, admin_passwd, admin_username]:
print('Creating superuser...')
user = User.objects.get_or_create(email=admin_email,
username=admin_username)[0]
user.set_password(admin_passwd)
user.is_superuser = True
user.is_staff = True
user.save()
print('Done!')
else:
print('Missing ADMIN_EMAIL, ADMIN_USERNAME or ADMIN_PASSWORD '
'environment variable.')
sys.exit(1)
def update_sites():
from django.contrib.sites.models import Site
import re
site = Site.objects.get_current()
site_domain = os.environ.get('SITE_DOMAIN', None)
site_name = os.environ.get('SITE_NAME', None)
if None not in [site_domain, site_name]:
print('Updating site infos...')
site_domain = re.sub('^(http|https)://', '', site_domain)
site.domain, site.name = site_domain, site_name
site.save()
print('Done!')
else:
print('Missing SITE_DOMAIN or SITE_NAME environment variable.')
sys.exit(2)
if __name__ == '__main__':
django.setup()
update_sites()