Total Complexity | 2 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import os |
||
2 | |||
3 | from django.core.management.base import BaseCommand |
||
4 | from django.contrib.auth.models import User |
||
5 | |||
6 | |||
7 | class Command(BaseCommand): |
||
8 | """Performs initial setup.""" |
||
9 | def handle(self, *args, **kwargs): |
||
10 | username = os.environ['SUPERUSER_NAME'] |
||
11 | password = os.environ['SUPERUSER_PASSWORD'] |
||
12 | email = os.environ['SUPERUSER_EMAIL'] |
||
13 | |||
14 | defaults = { |
||
15 | 'email': email, |
||
16 | 'is_superuser': True, |
||
17 | 'is_staff': True, |
||
18 | } |
||
19 | |||
20 | superuser, created = User.objects.update_or_create( |
||
21 | username=username, |
||
22 | defaults=defaults, |
||
23 | ) |
||
24 | |||
25 | superuser.set_password(password) |
||
26 | |||
27 | if created: |
||
28 | superuser.save() |
||
29 | self.stdout.write('Successfully created superuser %s.' % username) |
||
30 | else: |
||
31 | self.stdout.write('Superuser %s updated.' % username) |
||
32 |