Exemplo n.º 1
0
    def handle(self, *args, **options):
        username = options.get('username', None)
        email = options.get('email', None)
        password = options.get('password', None)
        fullname = options.get('fullname', None)

        if not username or not email or not password or not fullname:
            raise CommandError("You must specify all the arguments.")

        try:
            if options.get('is_superuser'):
                user = User.objects.create_superuser(username, email, password)
            else:
                user = User.objects.create_user(username, email, password)

            user.first_name = fullname
            user.save()

            from booki.account.models import UserProfile
            user_profile = UserProfile(user=user)
            user_profile.save()
        except:
            raise CommandError("Could not create the user.")