<commit_before>from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand, CommandError
from django.utils import timezone


class Command(BaseCommand):
    help = "Create a user with a specified username and password. User will be created as staff."

    def add_arguments(self, parser):
        parser.add_argument('-u', '--username', dest='username', required=True)
        parser.add_argument('-p', '--password', dest='password', required=True)

    def handle(self, *args, **options):
        User = get_user_model()

        username = options['username']
        password = options['password']

        user, created = User.objects.get_or_create(
            username=username, defaults=dict(last_login=timezone.now(), is_staff=True)
        )
        if not created:
            raise CommandError('Username %s is already taken.' % username)

        user.set_password(password)
        user.save()
        self.stdout.write(self.style.SUCCESS('User %s has been created.' % username))<commit_msg>Allow setting email when creating a staff account.<commit_after>from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand, CommandError
from django.utils import timezone


class Command(BaseCommand):
    help = "Create a user with a specified username and password. User will be created as staff."

    def add_arguments(self, parser):
        parser.add_argument('-u', '--username', dest='username', required=True)
        parser.add_argument('-p', '--password', dest='password', required=True)
        parser.add_argument('-e', '--email', dest='email', required=True)

    def handle(self, *args, **options):
        User = get_user_model()

        username = options['username']
        password = options['password']
        email = options['email']

        user, created = User.objects.get_or_create(
            username=username,
            email=email,
            defaults=dict(last_login=timezone.now(), is_staff=True),
        )
        if not created:
            raise CommandError('Username %s is already taken.' % username)

        user.set_password(password)
        user.save()
        self.stdout.write(self.style.SUCCESS('User %s has been created.' % username))
{'fraction_non_alphanumeric': 0.11816578483245149, 'fraction_numerical': 0.0, 'mean_word_length': 3.1786372007366483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '935106', 'n_tokens_mistral': 609, 'n_tokens_neox': 596, 'n_words': 165}