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:
- Spreadsheet that contains sheets with 'Deferral Form Responses' and the 'Deferrals' sheets, that is being processed.
- 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:
- Run a management command. For example:
./manage.py process_deferral_requests -i "<spreadsheet id>"
- 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
Release history Release notifications | RSS feed
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
File details
Details for the file mitol-django-google-sheets-deferrals-2023.6.9.tar.gz
.
File metadata
- Download URL: mitol-django-google-sheets-deferrals-2023.6.9.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0da60b7be8630711db6f0fc068dae5413b9348327bb2969059b8c9e5b6ec445 |
|
MD5 | e12eedb99de984710f557d5ddc5740eb |
|
BLAKE2b-256 | 970d9437d2f41bfcb8cc97b7db790de65244c230a5d182a02f963db3796a427d |
File details
Details for the file mitol_django_google_sheets_deferrals-2023.6.9-py3-none-any.whl
.
File metadata
- Download URL: mitol_django_google_sheets_deferrals-2023.6.9-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7090355790464ba33f6cfc9a4aa492d63e28e6874a81aeab5cc0ef84c73e8e5 |
|
MD5 | 6bb5ae895899a115c9968e3e80ec2055 |
|
BLAKE2b-256 | 834280a7b55d8e83e7154e30708fe5bb48e9f43c1a45ccca27ede03601be90d8 |