Command.handle()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
nop 3
dl 0
loc 23
rs 9.6
c 0
b 0
f 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