Conditions | 2 |
Total Lines | 23 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import os |
||
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 |