Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get application parameter inside an Open edX Xblock

Tags:

openedx

Im developing an OpenEdx Xblock.
I need to keep a value amongst all the users and all the xblocks. This value could change eventually, but only by the server admin.
My idea is to create new param in cms.env.json, and retrieve that param in my xblock. I haven't found documentation for this subject.

like image 527
mmartinez Avatar asked Jan 31 '26 06:01

mmartinez


1 Answers

The proper way to do that would be to store the setting in an XBlock field with the following scope:

BlockScope = TYPE
UserScope = NONE

(See the documentation on xblock scopes: http://edx.readthedocs.io/projects/xblock/en/latest/fields.html#xblock.fields.Scope)

Unfortunately, such a scope does not exist... So you are stuck with using django settings. If you wish to store this setting in the *.env.json files, then this is how you can read the value from inside the xblock:

from django.conf import settings
yourfeature = settings.FEATURES.get('yourfeature', 'defaultvalue')

Don't forget to store this feature value both in lms.env.json and cms.env.json! (provided you need this feature both in the LMS and the CMS)

like image 156
Régis B. Avatar answered Feb 03 '26 06:02

Régis B.