Package: openedx-plugin-example
Open edX Plugin ExamplesA curated collection of code samples for extending the functionality of an Open edX installation using its built-in plugin architecture.Technical features that are showcased in this repo include:Open edX Django configuration settingsOpen edX Django urlsOpen edX Django loggingOpen edX Django signalsOpen edX Django RestFramework custom apiDjango app setupDjango modelsDjango and Mako templatingDjango static assetsDjango AdminDjango middlewareDjango manage.py custom commandsDjango Waffle flagsPython environment variablesHow to bundle multiple plugins in a single pip packageHow to redirect Open edX urls in lms and cms to endpoints created in this pluginHow to automatically initialize Django model data during app startupAdding unit tests to plugin codeSemantic version controlPre-commit with linting by flake8 and black, both of which are configured to match the opinionated styling that you'll find in Open edX repositoriespip configuration, requirements, constraints, setup.py, pyproject.tomlPublishing to PyPiOpen edX Plugins in this Repositoryopenedx_pluginDemonstrates how to create an all-in-one Open edX plugin, with a heterogeneous collection of custom feature additions, including:A custom third party authenticationOauth2 client backend.Extendingnew user registrationfunctionality. Demonstrates how to leverage Django Signals to extend basic native Open edX operations.Extending thelogin functionalityImplementing arest apifrom scratch that is accessible from an LMS url.Advanced Internationalization:customizing static page linksbased on the language locale settingopenedx_plugin_apiImplements a full-featuredREST APIwhich is built from snippets of Open edX's built-in rest api libraries. Demonstrates the following:Best practices with Django RestFramework for Open edXAdding custom URL endpoints to LMSAdding Django Admin viewsCreating custom Django models for your pluginHow to create custom entries in the openedx app logHow to leverage Django Signals to create customized event-driven featuresHow to implement Waffle Switches to control optional features at run-timeopenedx_plugin_cmsImplements acustom course audit reportin Course Management Studio that depends on a backend Python process to iterate the course content. This process is highly instructive about the Open edX course object hierarchy. This plugin demonstrates the following:Adding custom URL endpoints to Course Management StudioAdding Django Admin viewsAdding custom manage.py commands to CMSCreating custom Django models for your pluginHow to create custom entries in the openedx app logHow to leverage Django Signals to create customized event-driven featuresHow to implement Waffle Switches to control optional features at run-timeAdvanced usage of Mako templating within an Open edX pluginHow to programatically iterate and inspect course contentHow to leverage Open edX object cachingopenedx_plugin_mobile_apiImplements a modified version of the Open edX LMS Mobile REST API. This plugin illustrates best practices for modifying edx-platform source code without actually forking this repository. Demonstrates the following:How to implement Django middleware to modify the destination of existing LMS url endpointsBest practices with Django RestFramework for Open edXGetting StartedInstall using TutorSeeInstalling extra xblocks and requirementstutorconfigsave# to ensure that tutor's root folder system has been createdecho"git+https://github.com/lpm0073/openedx-plugin-example.git">>"$(tutorconfigprintroot)/env/build/openedx/requirements/private.txt"cat"$(tutorconfigprintroot)/env/build/openedx/requirements/private.txt"tutorimagesbuildopenedx
tutorlocalquickstart# you'll also need to run this on your very first install# -----------------------------------------------------------------------------# 1. run migrationstutorlocalrunlms./manage.pylmsmakemigrations
tutorlocalrunlms./manage.pylmsmigrate
tutorlocalruncms./manage.pycmsmakemigrations
tutorlocalruncms./manage.pycmsmigrate# 2. add configuration data to custom modelstutorlocalrunlms./manage.pylmsopenedx_plugin_init
tutorlocalrunlms./manage.pylmsopenedx_plugin_api_init
tutorlocalrunlms./manage.pylmsopenedx_plugin_mobile_api_init
tutorlocalruncms./manage.pycmsopenedx_plugin_cms_initNotes About Django-WaffleEach of these four Open edX plugins usedjango-waffleto toggle features on and off. While edx-platform also uses waffle switches, you should note that they separately manage a wrapper project namededx-toggles, and therefore the source code in this repo interacts with both of these.Waffle switches in each of these four plugins are automatically initialized. You'll therefore find the switches in the LMS Django Admin console (admin/waffle/switch/) of your Open edX installation. Additionally, you'll find the raw MySL database records in the waffle_switch tableLook for app startup entries in the LMS app log for diagnostics information about the state of each waffle switchDocumentationDocumentation is available here:DocumentationSupportTo get community support, go to the official Open edX discussion forum:https://discuss.openedx.org.ContributingWe welcome contributions! openedx-plugin-example is part of thecookiecutter-openedxproject. Pull requests are welcome in all repos belonging to this organization. You can also contactLawrence McDanieldirectly.Getting Started With Local developmentUse the same virtual environment that you use for edx-platformEnsure that your Python interpreter to 3.8xinstall black:https://pypi.org/project/black/install flake8:https://flake8.pycqa.org/en/latest/install flake8-coding:https://pypi.org/project/flake8-coding/# Run these from within your edx-platform virtual environmentpython3-mvenvvenvsourcevenv/bin/activatecd/path/to/edx-platform
pipinstall-rrequirements/edx/base.txt
pipinstall-rrequirements/edx/coverage.txt
pipinstall-rrequirements/edx/development.txt
pipinstall-rrequirements/edx/pip-tools.txt
pipinstall-rrequirements/edx/testing.txt
pipinstall-rrequirements/edx/doc.txt
pipinstall-rrequirements/edx/paver.txt

pipinstallpre-commitblackflake8
pre-commitinstallLocal development good practicesrunblackon modified code before committing.runflake8 . --count --select=E9,F63,F7,F82 --show-source --statisticsrunflake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statisticsrunpre-commit run --all-filesbefore pushing. see:https://pre-commit.com/edx-platform dependenciesTo avoid freaky version conflicts in prod it's a good idea to install all of the edx-platform requirements to your local dev virtual environment.requirements/edx/base.txtrequirements/edx/develop.txt,requirements/edx/testing.txtAt a minimum this will give you the full benefit of your IDE's linter.