2020-04-23 13:29:00 +00:00
|
|
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2020-02-25 18:20:39 +00:00
|
|
|
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
2020-04-23 13:29:00 +00:00
|
|
|
def add_arguments(self, parser):
|
|
|
|
parser.add_argument('username', nargs='+', type=str)
|
|
|
|
parser.add_argument('-S', "--SUPER", action='store_true', help='make superuser')
|
|
|
|
parser.add_argument('-s', "--STAFF", action='store_true', help='make staff')
|
2020-02-25 18:20:39 +00:00
|
|
|
|
2020-04-23 13:29:00 +00:00
|
|
|
def handle(self, *args, **kwargs):
|
2020-02-25 18:20:39 +00:00
|
|
|
for uname in kwargs["username"]:
|
|
|
|
user = User.objects.get(username=uname)
|
|
|
|
user.is_active = True
|
2020-04-23 13:29:00 +00:00
|
|
|
if kwargs['STAFF']:
|
2021-04-14 13:18:24 +00:00
|
|
|
if kwargs['verbosity'] > 0:
|
|
|
|
self.stdout.write(f"Add {user} to staff users...")
|
2020-02-25 18:20:39 +00:00
|
|
|
user.is_staff = True
|
2020-04-23 13:29:00 +00:00
|
|
|
if kwargs['SUPER']:
|
2021-04-14 13:18:24 +00:00
|
|
|
if kwargs['verbosity'] > 0:
|
|
|
|
self.stdout.write(f"Add {user} to superusers...")
|
2020-04-23 13:29:00 +00:00
|
|
|
user.is_superuser = True
|
2020-02-25 18:20:39 +00:00
|
|
|
user.save()
|