loadAdminUser.py 831 Bytes
Newer Older
1
from base_app.models import User
2
import os
Florent Chehab's avatar
Florent Chehab committed
3
4
5
6


class LoadAdminUser(object):
    def __init__(self):
Florent Chehab's avatar
Florent Chehab committed
7
8
        """
        Creating admin user by creating a user and setting is_staff is True
Florent Chehab's avatar
Florent Chehab committed
9
        didn't enable access to the admin system for an unknown reason.
Florent Chehab's avatar
Florent Chehab committed
10
11
12
13
14
15
16
        Need to use create_superuser.
        """
        user = User.objects.filter(username="admin")
        if len(user) > 0:
            self.admin = user[0]
        else:
            User.objects.create_superuser(
17
18
19
                username=os.environ["DJANGO_ADMIN_USERNAME"],
                email="null@null.fr",
                password=os.environ["DJANGO_ADMIN_PASSWORD"],
Florent Chehab's avatar
Florent Chehab committed
20
            )
21
22
23
            self.admin = User.objects.filter(
                username=os.environ["DJANGO_ADMIN_USERNAME"]
            )[0]
Florent Chehab's avatar
Florent Chehab committed
24

Florent Chehab's avatar
Florent Chehab committed
25
    def get(self) -> User:
Florent Chehab's avatar
Florent Chehab committed
26
        return self.admin