openedx.core.djangoapps.user_api.management.commands package

Contents

openedx.core.djangoapps.user_api.management.commands package#

Submodules#

openedx.core.djangoapps.user_api.management.commands.bulk_user_org_email_optout module#

One-off script to opt-out users for email from orgs.

Input: A CSV file with a user_id,org pair per line. For example:

1962921,FooX 5506350,BarX 5709986,FooX

Lines formatted with a double-quoted org also work fine, such as:

5506350,”BarX”

Opts-out every specified user/org combo row from email by setting the ‘email-optin’ tag to ‘False’. If the user/org combo does not currently exist in the table, a row will be created for it which will be have the ‘email-optin’ tag set to ‘False’.

class openedx.core.djangoapps.user_api.management.commands.bulk_user_org_email_optout.Command(stdout=None, stderr=None, no_color=False, force_color=False)#

Bases: BaseCommand

One-off script to opt-out users for email from orgs.

Input: A CSV file with a user_id,org pair per line. For example:

1962921,FooX 5506350,BarX 5709986,FooX

Lines formatted with a double-quoted org also work fine, such as:

5506350,”BarX”

Opts-out every specified user/org combo row from email by setting the ‘email-optin’ tag to ‘False’. If the user/org combo does not currently exist in the table, a row will be created for it which will be have the ‘email-optin’ tag set to ‘False’.

DEFAULT_CHUNK_SIZE = 1000#
DEFAULT_SLEEP_BETWEEN_OPTOUTS = 0.0#
add_arguments(parser)#

Entry point for subclassed commands to add custom arguments.

handle(*args, **options)#

Execute the command.

help = 'One-off script to opt-out users for email from orgs.\n\nInput: A CSV file with a user_id,org pair per line. For example:\n\n1962921,FooX\n5506350,BarX\n5709986,FooX\n\nLines formatted with a double-quoted org also work fine, such as:\n\n5506350,"BarX"\n\nOpts-out every specified user/org combo row from email by setting the \'email-optin\' tag to \'False\'.\nIf the user/org combo does not currently exist in the table, a row will be created for it which\nwill be have the \'email-optin\' tag set to \'False\'.'#

openedx.core.djangoapps.user_api.management.commands.cancel_user_retirement_request module#

Use this mgmt command when a user requests retirement mistakenly, then requests for the retirement request to be cancelled. The command can’t cancel a retirement that has already commenced - only pending retirements.

class openedx.core.djangoapps.user_api.management.commands.cancel_user_retirement_request.Command(stdout=None, stderr=None, no_color=False, force_color=False)#

Bases: BaseCommand

Implementation of the cancel_user_retirement_request command.

add_arguments(parser)#

Entry point for subclassed commands to add custom arguments.

handle(*args, **options)#

Execute the command.

help = 'Cancels the retirement of a user who has requested retirement - but has not yet been retired.'#

openedx.core.djangoapps.user_api.management.commands.create_user_gdpr_testing module#

Create a user with GDPR P1 PII for manual testing. Enrolls the user in the DemoX course. Optionally takes in username, email, and course UUID arguments.

class openedx.core.djangoapps.user_api.management.commands.create_user_gdpr_testing.Command(stdout=None, stderr=None, no_color=False, force_color=False)#

Bases: BaseCommand

Create a user with GDPR P1 PII for manual testing. Enrolls the user in the DemoX course. Optionally takes in username, email, and course UUID arguments.

add_arguments(parser)#

Entry point for subclassed commands to add custom arguments.

handle(*args, **options)#

Execute the command.

help = 'Create a user with GDPR P1 PII for manual testing.\nEnrolls the user in the DemoX course.\nOptionally takes in username, email, and course UUID arguments.'#

openedx.core.djangoapps.user_api.management.commands.email_opt_in_list module#

Generate a list indicating whether users have opted in or out of receiving email from an org.

Email opt-in is stored as an org-level preference. When reports are generated, we need to handle:

  1. Org aliases: some organizations might have multiple course key “org” values.

    We choose the most recently set preference among all org aliases. Since this information isn’t stored anywhere in edx-platform, the caller needs to pass in the list of orgs and aliases.

  2. No preference set: Some users may not have an opt-in preference set

    if they enrolled before the preference was introduced. These users are opted in by default.

  3. Restricting to a subset of courses in an org: Some orgs have courses

    that we don’t want to include in the results (e.g. EdX-created test courses). Allow the caller to explicitly specify the list of courses in the org.

The command will always use the read replica database if one is configured.

class openedx.core.djangoapps.user_api.management.commands.email_opt_in_list.Command(stdout=None, stderr=None, no_color=False, force_color=False)#

Bases: BaseCommand

Generate a list of email opt-in values for user enrollments.

DEFAULT_DATETIME_STR = '2014-12-01 00:00:00'#
OUTPUT_FIELD_NAMES = ['user_id', 'username', 'email', 'full_name', 'course_id', 'is_opted_in_for_email', 'preference_set_datetime']#
QUERY_INTERVAL = 1000#
add_arguments(parser)#

Entry point for subclassed commands to add custom arguments.

handle(*args, **options)#

Execute the command.

Parameters:
  • file_path (str) – Path to the output file.

  • *org_list (unicode) – List of organization aliases.

Keyword Arguments:

courses (unicode) – Comma-separated list of course keys. If provided, include only these courses in the results.

Raises:

CommandError

help = 'Generate a list of email opt-in values for user enrollments.'#
openedx.core.djangoapps.user_api.management.commands.email_opt_in_list.chunks(sequence, chunk_size)#

openedx.core.djangoapps.user_api.management.commands.migrate_user_profile_langs module#

Migrates user preferences from one language code to another in batches. Dark lang preferences are not affected.

class openedx.core.djangoapps.user_api.management.commands.migrate_user_profile_langs.Command(stdout=None, stderr=None, no_color=False, force_color=False)#

Bases: BaseCommand

Implementation of the migrate command

add_arguments(parser)#

Entry point for subclassed commands to add custom arguments.

handle(*args, **options)#

Execute the command.

help = 'Migrate all user language preferences (excluding dark languages) from one language code to another.'#

openedx.core.djangoapps.user_api.management.commands.populate_enterprise_learner_current_job module#

Management command for populaing current job of learners in learner profile.

class openedx.core.djangoapps.user_api.management.commands.populate_enterprise_learner_current_job.Command(stdout=None, stderr=None, no_color=False, force_color=False)#

Bases: BaseCommand

Command to populate current job of learners in extended learner profile.

This command will fetch the current job of learners from course-discovery service and populate it in the extended learner profile in edx-platform. This command is supposed to be run only once in the system.

Example usage:

$ # Update the current job of learners. $ ./manage.py lms populate_enterprise_learner_current_job

TOTAL_USERS_COUNT = 0#
TOTAL_USERS_UPDATED = 0#
handle(*args, **options)#

Handle the command.

Parameters:
  • *args – Variable length argument list.

  • **options – Arbitrary keyword arguments.

help = 'Populates current job of learners in extended learner profile.'#

openedx.core.djangoapps.user_api.management.commands.populate_retirement_states module#

Take the list of states from settings.RETIREMENT_STATES and forces the RetirementState table to mirror it.

We use a foreign keyed table for this instead of just using the settings directly to generate a choices tuple for the model because the states need to be configurable by open source partners and modifying the choices for a model field causes new migrations to be generated, with a variety of unpleasant follow-on effects for the partner when upgrading the model at a later date.

class openedx.core.djangoapps.user_api.management.commands.populate_retirement_states.Command(stdout=None, stderr=None, no_color=False, force_color=False)#

Bases: BaseCommand

Implementation of the populate command

add_arguments(parser)#

Entry point for subclassed commands to add custom arguments.

handle(*args, **options)#

Execute the command.

help = 'Populates the RetirementState table with the states present in settings.'#

openedx.core.djangoapps.user_api.management.commands.retire_user module#

class openedx.core.djangoapps.user_api.management.commands.retire_user.Command(stdout=None, stderr=None, no_color=False, force_color=False)#

Bases: BaseCommand

Manually move a user into the retirement queue, so that they can be picked up by the user retirement pipeline. This should only be done in the case that a user has tried and is unable to delete their account via the UI.

Most of this code has been lifted from openedx/core/djangoapps/user_api/accounts/views

As this is a fairly sensitive operation, we want to make sure that human error is accounted for. In order to make sure that something like a typo during command invocation does not result in the retirement of a different user, you must supply both the username and email address linked to the user account.

add_arguments(parser)#

Entry point for subclassed commands to add custom arguments.

append_users_lists(file_handler, user_model)#

Function to extract users list from CSV files.

check_user_exist(user_model, userfile, user_name, useremail)#

Function to check if user exists. This function will execute for userfile or user_name and useremail.

Parameters:
  • userfile – file that have username and email of users to be retired

  • user_name – username of user to be retired

  • useremail – email of user to be retired

handle(*args, **options)#

Execute the command.

openedx.core.djangoapps.user_api.management.commands.sync_hubspot_contacts module#

Management command to sync platform users with hubspot ./manage.py lms sync_hubspot_contacts ./manage.py lms sync_hubspot_contacts –initial-sync-days=7 –batch-size=20

class openedx.core.djangoapps.user_api.management.commands.sync_hubspot_contacts.Command(stdout=None, stderr=None, no_color=False, force_color=False)#

Bases: BaseCommand

Command to create contacts in hubspot for those partner who has enabled hubspot integration. This command is suppose to sync contact with hubspot on daily basis.

add_arguments(parser)#

Definition of arguments this command accepts

handle(*args, **options)#

Main command handler

help = 'Command to create contacts in hubspot for those partner who has enabled hubspot integration.\nThis command is suppose to sync contact with hubspot on daily basis.'#

Module contents#