38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
|
# Society Self-Service
|
||
|
# Copyright © 2018-2019 Yingtong Li (RunasSudo)
|
||
|
#
|
||
|
# This program is free software: you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU Affero General Public License as published by
|
||
|
# the Free Software Foundation, either version 3 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU Affero General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU Affero General Public License
|
||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
|
||
|
from django.core.management.base import BaseCommand, CommandError
|
||
|
|
||
|
from django.contrib.auth.models import User
|
||
|
|
||
|
class Command(BaseCommand):
|
||
|
help = 'Makes the user with the specified email an administrator'
|
||
|
|
||
|
def add_arguments(self, parser):
|
||
|
parser.add_argument('email')
|
||
|
|
||
|
def handle(self, *args, **options):
|
||
|
try:
|
||
|
user = User.objects.get(email=options['email'])
|
||
|
except User.DoesNotExist:
|
||
|
raise CommandError('No user with this email')
|
||
|
|
||
|
user.is_staff = True
|
||
|
user.is_superuser = True
|
||
|
user.save()
|
||
|
|
||
|
self.stdout.write(self.style.SUCCESS('Success'))
|