create_smarter_admin

This module provides a Django management command to create or update a superuser (“Smarter admin”) account, user profile, and a corresponding API key for the platform.

Classes

Command

Implements the logic for the manage.py create_smarter_admin command.

Command-line Arguments

-u, –usernamestr, optional

The username for the new superuser (defaults to value from settings).

-e, –emailstr, optional

The email address for the new superuser (defaults to username@domain).

-p, –passwordstr, optional

The password for the new superuser. If not specified, a random password is generated.

Functionality

  • Ensures there is a platform admin account in the system, fully populated.

  • Creates or updates User and UserProfile for the superuser.

  • Creates a default AccountContact if absent.

  • Creates a new API key (auth token) for the superuser if one does not exist, and emails its value to the superuser’s email address. The value is never printed or logged, and can’t be recovered, so if the email can’t be sent, create another key with manage.py create_api_key.

  • Most account and contact attributes are populated from configuration settings.

Usage Example

python manage.py create_smarter_admin –username=admin –email=admin@example.com –password=s3cret

class smarter.apps.account.management.commands.create_smarter_admin.Command(stdout=None, stderr=None, no_color=False, force_color=False)[source]

Bases: SmarterCommand

Create a new Smarter superuser.

add_arguments(parser)[source]

Add arguments to the command.

email_api_key(user, auth_token, token_key)[source]

Email a new api key’s value to its owner.

The value is shown only in this email: it is never printed or logged, and Smarter keeps only its hash. The platform’s admin gets no blind copy, because the email carries a secret.

Parameters:
  • user (User) – the api key’s owner, the recipient.

  • auth_token (SmarterAuthToken) – the new api key.

  • token_key (str) – the api key’s value.

Return type:

bool

Returns:

True if the email was sent.

handle(*args, **options)[source]

Create the superuser account.