-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨(edx_imports) add management command populate_certificate_signatory
For several imported degree certificates signatory is not set. We create a management command to try to populate this missing information with ease.
- Loading branch information
Showing
7 changed files
with
616 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/backend/joanie/edx_imports/management/commands/populate_certificate_signatory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"""populate_certificate_signatory command module""" | ||
|
||
import logging | ||
|
||
from django.core.management import BaseCommand | ||
|
||
from joanie.edx_imports.checks import ( | ||
check_import_db_connections, | ||
check_import_env, | ||
check_openedx_host, | ||
) | ||
from joanie.edx_imports.tasks import populate_signatory_certificates_task | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Retrieve certificate without signatory then try to populate missing signatory""" | ||
|
||
def add_arguments(self, parser): | ||
"""Add arguments to the command""" | ||
parser.add_argument( | ||
"--skip-check", | ||
action="store_true", | ||
default=False, | ||
help="Skip check the env vars and db connections", | ||
) | ||
parser.add_argument( | ||
"--id", | ||
type=str, | ||
help="To populate signatory for a specific certificate", | ||
) | ||
parser.add_argument( | ||
"--course-id", | ||
type=str, | ||
help="To populate signatory for all certificates of a specific course", | ||
) | ||
|
||
def handle(self, *args, **options): | ||
"""Handle the command""" | ||
|
||
skip_check = options.get("skip_check") | ||
certificate_id = options.get("id") | ||
course_id = options.get("course_id") | ||
|
||
if not skip_check: | ||
logger.info("Checking the environment and database connections...") | ||
check_result = check_import_env(self.style) | ||
check_result = check_openedx_host(self.style) and check_result | ||
check_result = check_import_db_connections(self.style) and check_result | ||
if not check_result: | ||
logger.error(self.style.ERROR("\nCheck failed")) | ||
continue_import = input( | ||
"\nDo you want to continue importing data? (yes/no): " | ||
) | ||
if continue_import.lower() not in ["yes", "y"]: | ||
return | ||
logger.warning( | ||
self.style.WARNING("Continuing import despite failed checks") | ||
) | ||
|
||
populate_signatory_certificates_task.delay( | ||
certificate_id=certificate_id, course_id=course_id | ||
) | ||
|
||
logger.info("Populate signatory certificates tasks launched") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.