2016-11-08 10:14:26 +01:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
2016-11-10 11:11:27 +01:00
|
|
|
from ...models import User
|
2016-11-08 10:14:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
"""
|
2016-11-10 11:11:27 +01:00
|
|
|
Command to create an OpenSlides user.
|
2016-11-08 10:14:26 +01:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
|
|
|
help = "Creates an OpenSlides user."
|
2016-11-08 10:14:26 +01:00
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
2019-01-06 16:22:33 +01:00
|
|
|
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.")
|
2020-01-04 15:42:11 +01:00
|
|
|
parser.add_argument("--email", help="The email address of the new user.")
|
2016-11-08 10:14:26 +01:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
user_data = {
|
2019-01-06 16:22:33 +01:00
|
|
|
"first_name": options["first_name"],
|
|
|
|
"last_name": options["last_name"],
|
|
|
|
"default_password": options["password"],
|
2020-01-04 15:42:11 +01:00
|
|
|
"email": options["email"] or "",
|
2016-11-08 10:14:26 +01:00
|
|
|
}
|
2019-01-06 16:22:33 +01:00
|
|
|
user = User.objects.create_user(
|
2019-03-19 20:26:12 +01:00
|
|
|
options["username"], options["password"], skip_autoupdate=True, **user_data
|
2019-01-06 16:22:33 +01:00
|
|
|
)
|
|
|
|
if options["groups_id"].isdigit():
|
|
|
|
user.groups.add(int(options["groups_id"]))
|