diff --git a/backend/census_historical_migration/historic_data_loader.py b/backend/census_historical_migration/historic_data_loader.py index 283c2693e6..015cb30e05 100644 --- a/backend/census_historical_migration/historic_data_loader.py +++ b/backend/census_historical_migration/historic_data_loader.py @@ -1,8 +1,10 @@ from .models import ELECAUDITHEADER as AuditHeader +from .models import ReportMigrationStatus from .workbooklib.end_to_end_core import run_end_to_end from django.contrib.auth import get_user_model from django.core.paginator import Paginator +from django.utils import timezone User = get_user_model() @@ -34,6 +36,12 @@ def load_historic_data_for_year(audit_year, page_size, pages): result_log[(audit_year, submission.DBKEY)] = result total_count += 1 + migration_status = "SUCCESS" + if len(result["errors"]) > 0: + migration_status = "FAILURE" + + record_migration_status(audit_year, submission.DBKEY, migration_status) + if len(result["errors"]) > 0: error_count += 1 if total_count % 5 == 0: @@ -65,3 +73,12 @@ def create_or_get_user(): user.save() return user + + +def record_migration_status(audit_year, dbkey, status): + ReportMigrationStatus( + audit_year=audit_year, + dbkey=dbkey, + run_datetime=timezone.now(), + migration_status=status, + ).save() diff --git a/backend/census_historical_migration/management/commands/historic_data_migrator.py b/backend/census_historical_migration/management/commands/historic_data_migrator.py index 0f300654b4..e31ba14125 100644 --- a/backend/census_historical_migration/management/commands/historic_data_migrator.py +++ b/backend/census_historical_migration/management/commands/historic_data_migrator.py @@ -7,7 +7,10 @@ from census_historical_migration.workbooklib.excel_creation_utils import ( get_audit_header, ) -from census_historical_migration.historic_data_loader import create_or_get_user +from census_historical_migration.historic_data_loader import ( + create_or_get_user, + record_migration_status, +) from census_historical_migration.workbooklib.end_to_end_core import run_end_to_end from django.conf import settings @@ -52,6 +55,12 @@ def initiate_migration(self, dbkeys_str, years_str): run_end_to_end(user, audit_header, result) logger.info(result) + migration_status = "SUCCESS" + if len(result["errors"]) > 0: + migration_status = "FAILURE" + + record_migration_status(year, dbkey, migration_status) + def handle(self, *args, **options): dbkeys_str = options["dbkeys"] years_str = options["years"] diff --git a/docs/django-admin-operations.md b/docs/django-admin-operations.md new file mode 100644 index 0000000000..5a618c345e --- /dev/null +++ b/docs/django-admin-operations.md @@ -0,0 +1,43 @@ +# Django admin operations + +This is a how-to guide for common FAC Django admin operations. + +The Django admin interface path is `/admin/`; the production instance is at [https://app.fac.gov/admin/](https://app.fac.gov/admin/). + +To use it, you must have logged into the application and have an account that has been granted access. + +If you need to grant someone read-only access to the Django admin, see [Granting `staff` access](#granting-staff-access). + +If you need to investigate why a user cannot see or access a submission, see [Looking up access information by `report_id` or email address](#looking-up-access-information-by-report_id-or-email-address). + +If you need to investigate problems with a submission unrelated to access issues, see [Looking up submission information by `report_id` or UEI](#looking-up-submission-information-by-report_id-or-uei). + +## Granting `staff` access + +You must have `superuser` access to do this. + +1. Get the email address of the account to grant `staff` access to. +2. Go to [https://app.fac.gov/admin/users/staffuser/add](https://app.fac.gov/admin/users/staffuser/add), enter the email address, and click on the **SAVE** button. +3. Verify that the email address is in the list of users at [https://app.fac.gov/admin/users/staffuser/]([https://app.fac.gov/admin/users/staffuser/). +4. Confirm with the user in question that they can log into the Django admin site. + +## Looking up access information by `report_id` or email address + +You must have `staff` or `superuser` access to do this. + +1. Get the `report_id` of the submission or the email address in question. +2. Go to [https://app.fac.gov/admin/audit/access/](https://app.fac.gov/admin/audit/access/). +3. Enter the `report_id` or email address into the search field at the top of the page and hit enter. +4. You should now see only the list of `Access` entries associated with that `report_id` or email address. +5. The roles and email addresses are displayed here and are usually all that’s required. +6. If necessary, click on any of the entries in the **SAC** column in order to find more information about that `Access`. + +## Looking up submission information by `report_id` or UEI + +You must have `staff` or `superuser` access to do this. + +1. Get the `report_id` or UEI in question. +2. Go to [https://app.fac.gov/admin/audit/singleauditchecklist/](https://app.fac.gov/admin/audit/singleauditchecklist/). +3. Enter the `report_id` or UEI into the search field at the top of the page and hit enter. +4. You should now see only the list of `SingleAuditChecklist` entries associated with that `report_id` or UEI. +5. To see more information about a particular `SingleAuditChecklist`, click the number in the **ID** column.