Introduction
This document describes the different options available to you to add a new feature to the edX platform.
Note: If you have not contributed to edX before, be sure to read this guide: Process for Contributing Code.
Decide where to host your code
The first thing you should decide is where you will host your new feature. There are five options to consider which are listed here in order of preference:
- XBlocks allows you to define new types of components that can be used in courseware, e.g. new problem types
- For edX to consume your XBlock, it should just be added as a requirement to: https://github.com/edx/edx-platform/blob/master/requirements/edx/github.in
- Consider the following before choosing to create an XBlock:
- Testing of authoring views is challenging as there is no straightforward way to run with the block embedded in Studio
- There are aspects of XBlock integration into Studio that have not been completed, e.g.
- Examples of XBlocks:
- See the documentation below: Create a new XBlock in its own Git repository
- Create a new IDA (independently deployable application)
- If a feature doesn't need to be tightly integrated into Studio or the LMS then it can be built as an independent app
- It can make use of the Open edX ReST APIs to get any platform data that it requires
- IDAs are a good choice when:
- They need to scale independently of the edX platform
- They will be built, deployed and managed by a separate team
- LMS and Studio should continue unaffected even if the application goes down
- :
- There is more operational complexity for the community to deploy and manage your feature
- There are performance implications with introducing extra network calls
- There is more application complexity when working with related data from external APIs, e.g. joins and referential integrity must be implemented in the application layer
- Examples of IDAs:
- See the documentation below: Create a new IDA
- New Django apps can be implemented in a separate repo and pip installed into the platform
- A Django app in its own repository is a good choice when:
- it provides new services that will be consumed by other parts of the platform
- if it requires new UI for LMS or Studio, it provides it via extensions and does not introduce new URLs
- See OEP-12 for the recommended way to add pluggable user interfaces
- Add a new Django app to the edX platform
- If your feature cannot be built using the existing extension points, then it can be added directly to the edx-platform
- Consider the following:
- It would be better to introduce a platform extension point and then use it from a separate app
- It is best to build your new Django app in its own directory so that there is an option to move it into its own repo later
- Our current thinking is to add your new Django app to the directory
openedx/features
- See Web Fragments for the recommended way to add pluggable user interfaces
- Examples of Django apps in the edX platform:
- See the documentation below: Adding a new Django app to edx-platform
- Update the platform directly
- This is the option of last resort
- When should you update the platform
- When the feature you are implementing updates core functionality in fundamental ways
- When there are no extension points that you can use to build the functionality you need
- Consider the following before doing this:
- Features which update the platform directly require the most scrutiny in code review
- There is far more risk of unexpected fallout from your changes
- Consider whether it is possible to introduce a platform extension point and then use it
- Be sure to discuss your proposed approach with the Open edX community first to ensure that this is the best way to move forward
- Examples:
- See the documentation below: Update the platform directly
For more background when making this decision, see these architecture council meeting notes: 2015.09.23 - IDA discussion.
How to add a new XBlock in its own Git repository
How to create a new IDA
How to add a new Django app in its own Git repository
How to add a new Django app to the edX platform
These are the steps necessary for adding a new Django app-based feature, based on what was done to add the Teams feature to LMS.
- Create a new Django app, where all Python, mako and underscore templates, and JavaScript will live (note that there is an open story to allow sass files to also live in this app)
- Our current best practice it so put new features into the platform directory
openedx/features
- Create your Python view code, urls.py file, and unit tests
- If you have JavaScript and underscore templates:
- Put your JavaScript files inside of a static directory, namespaced by the name of your app (for instance,
teams/static/teams/js
). - As a best practice, use RequireJS and Backbone for your JavaScript
- Use Underscore to handle client-side templates and load them using RequireJS Text (example).
- Put your underscore templates inside the same namespaced static directory (for instance,
teams/static/teams/templates
). - Put your Jasmine unit tests inside a spec directory within the JS directory (for instance,
teams/static/teams/js/spec
). - To enable the Jasmine unit tests as part of running LMS unit tests:
- Add the names of your specs to
lms/static/js/spec/main.js
. - Add to src_paths, spec_paths, and fixture_paths in
lms/static/karma_lms.conf.js
(example). - Create a symbolic link in lms/static to the location of your static directory so that unit tests can find the appropriate files (example).
- For more details, see How to add a new page to LMS or Studio
- Add the name of your app to in
lms/envs/common.py
- Apps listed in OPTIONAL_APPS will be dynamically added to Django's INSTALLED_APPS if the app is present
- This is beneficial as some forks of Open edX might choose not to use your new feature
- If your feature will always be present in the platform, you can instead update INSTALLED_APPS directly
- For example: https://github.com/edx/edx-platform/blob/master/lms/envs/common.py#L2862
- This ensures that the Django pipeline will pick up all of the static assets found beneath your
static
directory - You can reference your static files as follows:
- In Mako, use
static.url
which resolves a path to the correct location in the Django static directory - In client-side code, you can use relative paths in RequireJS which will resolve to the correct location
- All other client-side URLs should be resolved on the server and then passed down to the client
- Don't assume that you can access a file directly with
/static/myApp/foo.jpg
because that bypasses the Django pipeline
- Add your urls to
lms/urls.py
, most likely behind a feature flag or configuration setting- Be sure to have a urls.py within your Django app, and then include it from the platform's urls.py
- Write bok choy acceptance tests in
common/test/acceptance
to verify that your plugin is working.
How to update the platform directly
- Determine that there is no better way to implement your feature, as core platform changes are hard to make and have approved
- Follow the contribution process to make a pull request against the platform: Process for Contributing Code
Implementing your new feature
Once you have chosen how to provide your new feature, you can add many different types of functionality: