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.12.19.tar.gz
.
File metadata
- Download URL: mitol-django-google-sheets-deferrals-2023.12.19.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26225aca252f3967b7429fee74089e4658ab539f64b168d07b221b9e74fdc3e7 |
|
MD5 | f464e00c1479110a09bb3003dfc0780b |
|
BLAKE2b-256 | e410c6dbc9312254961032b89d19a6c7da191baefef1521fedf94864b4c88bdf |
File details
Details for the file mitol_django_google_sheets_deferrals-2023.12.19-py3-none-any.whl
.
File metadata
- Download URL: mitol_django_google_sheets_deferrals-2023.12.19-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c41a7f607f555eecf145f9187a19d0c93340d990d2cb8d13e0718270737c4828 |
|
MD5 | 16e9733767e7de40de40a17b05c4b71a |
|
BLAKE2b-256 | eab1e198857613ebebd72774eaf95eec379182579b9b662a40ab07cde9d39b62 |