Package: mitol-django-google-sheets-deferrals
mitol-django-google-sheets-deferralsThis is the Open Learning Django Google Sheets library for handling deferral requests over Google SheetsSetupBefore you begin setting up this library make sure you set upmitol-django-google-sheetsfirst. Follow the instructionshere.Once you havemitol-django-google-sheetsinstalled, then:pip install mitol-django-google-sheets-deferralsInsettings.pyINSTALLED_APPS=[..."mitol.google_sheets_deferrals.apps.GoogleSheetsDeferralsApp",]MITOL_GOOGLE_SHEETS_DEFERRALS_PLUGINS=["ecommerce.plugins.DeferralPlugin"]Inecommerce/plugins.pyfrommitol.google_sheets_deferrals.hooksimporthookimplclassDeferralPlugin:@hookimpldefdeferrals_process_request(deferral_request:DeferralRequestRow)->DeferralResult:# TODO: look up the user/enrollment# TODO: unenroll user from and enroll toCreate your google sheets folderThe structure of the folder should look as the following:Spreadsheet that contains sheets with 'Deferral Form Responses' and the 'Deferrals' sheets, that is being processed.Request FormAsk a developer for a template folder to copy this structure.Add settings to your appSetMITOL_GOOGLE_SHEETS_DEFERRALS_REQUEST_WORKSHEET_IDin your .env file. It is required.Some settings have default values, which you might need to update, if your sheet is different.Description of settings (in addition to the ones described inmitol-django-google-sheets):MITOL_GOOGLE_SHEETS_DEFERRALS_REQUEST_WORKSHEET_IDThe IDs of the refund and deferral sheets in the change of enrollment spreadsheet. These can
be found by opening the spreadsheet, selecting the "Refunds" or "Deferrals" worksheets, and
copying down thegidvalue in the URL.Example:https://docs.google.com/spreadsheets/d/<MITOL_GOOGLE_SHEETS_ENROLLMENT_CHANGE_SHEET_ID>/edit#gid=<MITOL_GOOGLE_SHEETS_DEFERRALS_REQUEST_WORKSHEET_ID>MITOL_GOOGLE_SHEETS_DEFERRALS_PROCESSOR_COLThe zero-based index of the deferral change sheet column that contains the user that processed the rowMITOL_GOOGLE_SHEETS_DEFERRALS_COMPLETED_DATE_COLThe zero-based index of the deferral change sheet column that contains the row completion dateMITOL_GOOGLE_SHEETS_DEFERRALS_ERROR_COLThe zero-based index of the deferral change sheet column that contains row processing error messagesMITOL_GOOGLE_SHEETS_DEFERRALS_SKIP_ROW_COLThe zero-based index of the deferral change sheet column that indicates whether the row should be skippedMITOL_GOOGLE_SHEETS_DEFERRALS_FIRST_ROWThe first row (as it appears in the spreadsheet) of data that our scripts should consider processing in the deferral request spreadsheetUsageTo processing your google sheet with deferral requests simply add:deferral_request_handler=DeferralRequestHandler()results=deferral_request_handler.process_sheet()Here are two main ways that we are currently getting our Google Sheets Deferrals processed:Run a management command. For example:./manage.py process_deferral_requests -i "<spreadsheet id>"Set up a scheduled celery task. For example:frommitol.google_sheets_deferrals.apiimportDeferralRequestHandlerfrommain.celeryimportapp@app.taskdefprocess_deferral_requests():"""Task to process deferral requests from Google sheets"""deferral_request_handler=DeferralRequestHandler()ifnotdeferral_request_handler.is_configured():log.warning("MITOL_GOOGLE_SHEETS_* are not set")returndeferral_request_handler.process_sheet()Develper setupFor local development setup and testing please follow the instructionsDeveloper Setuphere.