Skip to main content

Library to handle Deferral requests using Google Sheets integrations in Django

Project description

mitol-django-google-sheets-deferrals

This is the Open Learning Django Google Sheets library for handling deferral requests over Google Sheets

Setup

Before you begin setting up this library make sure you set up mitol-django-google-sheets first. Follow the instructions here.

Once you have mitol-django-google-sheets installed, then:

pip install mitol-django-google-sheets-deferrals

In settings.py

INSTALLED_APPS = [
    ...
    "mitol.google_sheets_deferrals.apps.GoogleSheetsDeferralsApp",
]
MITOL_GOOGLE_SHEETS_DEFERRALS_PLUGINS = [
    "ecommerce.plugins.DeferralPlugin"
]

In ecommerce/plugins.py

from mitol.google_sheets_deferrals.hooks import hookimpl

class DeferralPlugin:
    @hookimpl
    def deferrals_process_request(deferral_request: DeferralRequestRow) -> DeferralResult:
        # TODO: look up the user/enrollment
        # TODO: unenroll user from and enroll to

Create your google sheets folder

The structure of the folder should look as the following:

  1. Spreadsheet that contains sheets with 'Deferral Form Responses' and the 'Deferrals' sheets, that is being processed.
  2. Request Form

Ask a developer for a template folder to copy this structure.

Add settings to your app

Set MITOL_GOOGLE_SHEETS_DEFERRALS_REQUEST_WORKSHEET_ID in 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 in mitol-django-google-sheets):

  • MITOL_GOOGLE_SHEETS_DEFERRALS_REQUEST_WORKSHEET_ID

    The 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 the gid value 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_COL

    The zero-based index of the deferral change sheet column that contains the user that processed the row

  • MITOL_GOOGLE_SHEETS_DEFERRALS_COMPLETED_DATE_COL

    The zero-based index of the deferral change sheet column that contains the row completion date

  • MITOL_GOOGLE_SHEETS_DEFERRALS_ERROR_COL

    The zero-based index of the deferral change sheet column that contains row processing error messages

  • MITOL_GOOGLE_SHEETS_DEFERRALS_SKIP_ROW_COL

    The zero-based index of the deferral change sheet column that indicates whether the row should be skipped

  • MITOL_GOOGLE_SHEETS_DEFERRALS_FIRST_ROW

    The first row (as it appears in the spreadsheet) of data that our scripts should consider processing in the deferral request spreadsheet

Usage

To 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:

  1. Run a management command. For example: ./manage.py process_deferral_requests -i "<spreadsheet id>"
  2. Set up a scheduled celery task. For example:
from mitol.google_sheets_deferrals.api import DeferralRequestHandler
from main.celery import app

@app.task
def process_deferral_requests():
    """
    Task to process deferral requests from Google sheets
    """
    deferral_request_handler = DeferralRequestHandler()
    if not deferral_request_handler.is_configured():
        log.warning("MITOL_GOOGLE_SHEETS_* are not set")
        return
    deferral_request_handler.process_sheet()

Develper setup

For local development setup and testing please follow the instructions Developer Setup here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file mitol_django_google_sheets_deferrals-2025.3.17.tar.gz.

File metadata

File hashes

Hashes for mitol_django_google_sheets_deferrals-2025.3.17.tar.gz
Algorithm Hash digest
SHA256 cffd148437c4290b9115965d195a5b9eded48b8d424d14b51a7cfcfbe0cedc02
MD5 3dc937be9038a7068eab163d782f53a3
BLAKE2b-256 3ccdc42e28a3ea5f5297d0f57ec9221ff25f72051cfcafeb3c11713d06a02ed8

See more details on using hashes here.

File details

Details for the file mitol_django_google_sheets_deferrals-2025.3.17-py3-none-any.whl.

File metadata

File hashes

Hashes for mitol_django_google_sheets_deferrals-2025.3.17-py3-none-any.whl
Algorithm Hash digest
SHA256 5256a43ae606d72c1c5a90c230af3e55b5fb4c7c6184de9a68f597d6ea7c2f28
MD5 c22fdf83f0df1a27e1a8a59e2a8de41c
BLAKE2b-256 8129dc98ad7ac916b70bbd82f87055a62ba20da81dd992eb32e83351e4a25a3d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page