OpenSlides/openslides/users/management/commands/createopenslidesuser.py

43 lines
1.2 KiB
Python
Raw Normal View History

from django.core.management.base import BaseCommand
2016-11-10 11:11:27 +01:00
from ...models import User
class Command(BaseCommand):
"""
2016-11-10 11:11:27 +01:00
Command to create an OpenSlides user.
"""
help = 'Creates an OpenSlides user.'
def add_arguments(self, parser):
parser.add_argument(
'first_name',
help='The first name of the new user.'
)
parser.add_argument(
'last_name',
help='The last name of the new user.'
)
parser.add_argument(
'username',
help='The username of the new user.'
)
parser.add_argument(
'password',
help='The password of the new user.'
)
parser.add_argument(
'groups_id',
help='The group id of the new user.'
)
def handle(self, *args, **options):
user_data = {
'first_name': options['first_name'],
'last_name': options['last_name'],
'default_password': options['password'],
}
user = User.objects.create_user(options['username'], options['password'], **user_data)
if options['groups_id'].isdigit():
user.groups.add(int(options['groups_id']))