Cloned DMOJ
This commit is contained in:
parent
f623974b58
commit
49dc9ff10c
513 changed files with 132349 additions and 39 deletions
32
judge/management/commands/adduser.py
Normal file
32
judge/management/commands/adduser.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from judge.models import Language, Profile
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'creates a user'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('name', help='username')
|
||||
parser.add_argument('email', help='email, not necessary to be resolvable')
|
||||
parser.add_argument('password', help='password for the user')
|
||||
parser.add_argument('language', nargs='?', default=settings.DEFAULT_USER_LANGUAGE,
|
||||
help='default language ID for user')
|
||||
|
||||
parser.add_argument('--superuser', action='store_true', default=False,
|
||||
help="if specified, creates user with superuser privileges")
|
||||
parser.add_argument('--staff', action='store_true', default=False,
|
||||
help="if specified, creates user with staff privileges")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
usr = User(username=options['name'], email=options['email'], is_active=True)
|
||||
usr.set_password(options['password'])
|
||||
usr.is_superuser = options['superuser']
|
||||
usr.is_staff = options['staff']
|
||||
usr.save()
|
||||
|
||||
profile = Profile(user=usr)
|
||||
profile.language = Language.objects.get(key=options['language'])
|
||||
profile.save()
|
Loading…
Add table
Add a link
Reference in a new issue