Skip to main content

Open edX: How To Install an XBlock

Learn how to install an Open edX XBlock code extension with this detailed step-by-step how-to guide. This step-by-step guide works for any XBlock. Let’s get started!

Summary

XBlock is the extensibility framework for Open edX. That is, it’s a framework that allows the open source software development community to extend and enhance edX to meet future needs. If you’re familiar with the content management system WordPress then, architecturally speaking, XBlocks are nearly identical to plugins. ExtensionEngine wrote this great blog article on XBlocks. However, a big difference between WordPress plugins and XBlocks is that installing them is a murky process. In this blog post I set out clarify and simplify the exact steps that are required to install any XBlock.
For this tutorial we’ll install a really cool XBlock named In-Video Quiz which, as the name implies, will abruptly pause a video to present the student with a problem. This XBlock was written by the Open edX programming team at Stanford University and is freely available on GitHub (https://github.com/Stanford-Online/xblock-in-video-quiz). Like many XBlocks that I’ve installed, the functionality works great, but the documentation is sparse. So, the In-Video Quiz is a great example for this blog post.
Before moving on I’ll point out a couple of things that might weigh on your installation choices. First, you can install XCode packages anywhere in your Ubuntu server. References to the code are bound during the automated installation process. But having said that, I would recommend that you NOT install XCode packages anywhere inside of the /edx subdirectory simply because doing this can complicate future platform software upgrades. That is, if you install you XBlock packages anywhere inside the /edx subdirectory, it might get overwritten during a future upgrade of any part of the Open edX platform.

Assumptions

  • Your Open edX instance is running from an AWS account
  • Your AWS EC2 instance is running on an Ubuntu 16.04 LTS server built from the Amazon Linux AMI
  • You have SSH access to your EC2 instance and sudo capability
  • You are generally familiar with GitHub packages (you’ve at least heard of them)
  • Your Open edX instance is substantially based on the guidelines published here: Native Open edX Ubuntu 16.04 64 bit Installation

1. Clone The GitHub Repository of the XBlock Package

Like Open edX itself, XBlocks are written in Python, and while I’m not a Python programmer myself, I will say that I’ve observed that the Python programming community tends to have a preferred way to do everything; and that includes for example, how Python programs should be installed. That being the case, a lot of Python programs (or all of them?) are stored as raw source code which one downloads in packages from repository platforms like GitHub to be compiled on the server using a variety of Python-specific installations tools. In the case of Open edX the preferred route seems to be a command line utility named pip (Python Installation Program). I’m a Python neophyte, just so you know. But regardless, pip is pretty awesome, and pretty stupid-proof.
All of this matters because XBlocks are written in Python and, as it happens, thanks in no small measure to the peculiarities of the Python community, there’s one single method of installation that works for all XBlocks. First, we need to clone the GitHub repository where our In-Video Quiz is stored. I can almost always find the GitHub repository by using Google. Once you find the repository, GitHub provides a 1-click way to copy the exact http URI of the repository, which we’ll use on the command line of our Ubuntu instance. Refer to the following screen shot for the location of the 1-click copy method:
Afterwards, paste the URI of the repository onto the command line so that you have a command line that looks like the following:
$ git clone https://github.com/Stanford-Online/xblock-in-video-quiz.git

2. Change Ownership of the Repository directory in Ubuntu

Cloning the GitHub repository simply means copying all of the files (and whatever else might be in the repository like say, images, mp3s, etc) to your Ubuntu file system.
I clone repositories into the Ubuntu home folder /home/ubuntu/ where I also store any and all other Open edX configuration files and scripts. However, feel free to clone the repository to whatever location in your file system you prefer as this (within reason) has no bearing on the installation process.
Once you’ve cloned the repository you’ll also need to change the folder ownership and group to edxapp. This is because we’ll install the code using the edxapp user, and if the source code itself doesn’t reside in a folder that’s owned by this user then the pip installation program will potentially complain.
$ sudo chown edxapp xblock-in-video-quiz
$ sudo chgrp edxapp xblock-in-video-quiz

3. Run the pip Installation Program

This is where the magic happens. We’re going to use pip (Python Installation Program) to install our XBlock. Python programmers are a thorough bunch. They not only think about their code’s functionality, but also the code dependencies of their code, and even the version compatibility. Ultimately, pip does all of this for us. Therefore, the specifics on how to run pip might seem underwhelming, but here it is:
$ sudo -u edxapp /edx/bin/pip.edxapp install /home/ubuntu/xblock-in-video-quiz
We now find ourselves in one of those, “the proof is left to the reader” moments. :/

4. Manually Compile Assets

It’s virtually assured that your XBlock will not yet work, even if the pip installation package reported that it installed successfully. That is because farther up the technology stack of Open edX there is more work to do that resides far beyond the purview of pip. Namely, we need to manually compile the Open edX assets. I’ll probably write a blog post about what this means since the need do this seems to arise so often. For now however, just do the following:
$ sudo -H -u edxapp bash
$ source /edx/app/edxapp/edxapp_env
$ cd /edx/app/edxapp/edx-platform
$ paver update_assets cms --settings=aws
$ paver update_assets lms --settings=aws
If this is your first time to manually compile assets that be aware that the process will take around 10 minutes to complete, and meanwhile, your Open edX platform will be offline to your teachers and students.

5. Restart the LMS and CMS

Any time you manually compile assets, you’ll also need to restart the LMS and CMS. The command lines to do this are as follows:
$ sudo /edx/bin/supervisorctl restart edxapp:
$ sudo /edx/bin/supervisorctl restart edxapp_worker:
This process takes around five minutes to complete. Meanwhile your teachers and students will not have access. Note that you can use the Linux command line “top” to view the progress of the restart process.
$ top
I confess that this is not particularly scientific, but, the following three screen shots demonstrate how to monitor and detect the precise state of your Open edX platform. Importantly, using “top” will enable you to know whether your Open edX platform is available to your users.
Shutting Down
Restarting
Running Normally

6. Enable The XBlock In Your Course

Adding your XBlock to a course involves four steps, three of which are standard with the latter two steps varying slightly depending on design choices made by the XBlock programmer. All of these steps are performed from within the Course Management Studio Application.
  1. Select the course which you want to install the XBlock. You need to have edit rights for the course.
  2. Choose “Configuration / Advanced Configuration” from the Course Studio menu bar
  3. Scroll to near the bottom of the next screen until you find “XBlocks”. You include the XBlock in your course by adding it’s technical name to a JSON array in this field. JSON arrays take the form ['Item1', 'Item2', 'Item3']. The square brackets are required. The technical name of the XBlock is often described in the Readme page in its GitHub repository. If not, you might need to ask the XBlock author. Don’t forget to save! After completing this step the XBlock should become visible in the Course’s tool palettes.
  4. Return to your course content and choose either “Advanced” or “Problem” from the “Add new Component” button bar at the bottom of the window. The Xblock will appear in either (or perhaps both) depending on how the programmer designed it.
  5. Specifics on configuring an instance of the XBlock will vary. However, XBlocks commonly refer to other course objects (aka course elements, aka course building blocks). You might see data fields in your XBlock referring to an “ID” value of object X in your course. The illustration below shows how to locate, and importantly, how to correctly these ID values to your XBlock.
I hope you found this helpful. Please help me improve this article by leaving a comment below. Thank you!

Popular posts from this blog

How to read or extract text data from passport using python utility.

Hi ,  Lets get start with some utility which can be really helpful in extracting the text data from passport documents which can be images, pdf.  So instead of jumping to code directly lets understand the MRZ, & how it works basically. MRZ Parser :                 A machine-readable passport (MRP) is a machine-readable travel document (MRTD) with the data on the identity page encoded in optical character recognition format Most travel passports worldwide are MRPs.  It can have 2 lines or 3 lines of machine-readable data. This method allows to process MRZ written in accordance with ICAO Document 9303 (endorsed by the International Organization for Standardization and the International Electrotechnical Commission as ISO/IEC 7501-1)). Some applications will need to be able to scan such data of someway, so one of the easiest methods is to recognize it from an image file. I 'll show you how to retrieve the MRZ information from a picture of a passport using the PassportE

How to generate class diagrams pictures in a Django/Open-edX project from console

A class diagram in the Unified Modeling Language ( UML ) is a type of static structure diagram that describes the structure of a system by showing the system’s classes, their attributes, operations (or methods), and the relationships among objects. https://github.com/django-extensions/django-extensions Step 1:   Install django extensions Command:  pip install django-extensions Step 2:  Add to installed apps INSTALLED_APPS = ( ... 'django_extensions' , ... ) Step 3:  Install diagrams generators You have to choose between two diagram generators: Graphviz or Dotplus before using the command or you will get: python manage.py graph_models -a -o myapp_models.png Note:  I prefer to use   pydotplus   as it easier to install than Graphviz and its dependencies so we use   pip install pydotplus . Command:  pip install pydotplus Step 4:  Generate diagrams Now we have everything installed and ready to generate diagrams using the comm

How to Remove course from Open-edX

Go to vagrant  => 1. In the edx-platform directory:  - cd /edx/app/edxapp/edx-platform 2. Run the following Django management command:   - sudo -u www-data /edx/bin/python.edxapp /edx/bin/manage.edxapp lms dump_course_ids --settings aws    - sudo -u www-data /edx/bin/python.edxapp /edx/bin/manage.edxapp lms dump_course_ids --settings=devstack 3. Find the course ID which you'd like to delete in the resulting list of course IDs. 4. Copy the course ID into the following command and run it:  - sudo -u www-data /edx/bin/python.edxapp /edx/bin/manage.edxapp cms delete_course <COURSE_ID> --settings aws  -   sudo -u www-data /edx/bin/python.edxapp /edx/bin/manage.edxapp cms delete_course <COURSE_ID> --settings=devstack  - You'll be asked to verify the deletion . To verify the deletion, run the command from step 2 above and ensure that the course ID is not in the list. Help reference : https://openedx.atlassian.net/wiki/spa