Files
edx-platform/openedx/core/djangoapps/xblock/apps.py
Braden MacDonald 1382bf8720 Save user state for Blockstore XBlocks in CSM, clean up CSM a bit (#21630)
This commit introduces the changes needed for XBlocks in Blockstore to save
their user state into CSM. Before this commit, all student state for Blockstore
blocks was ephemeral (in-process dict store).

Notes:

* The main risk factor of this PR is that it adds non-course keys to the
  course_id field in CSM. If any code (like analytics?) reads course keys
  directly out of CSM and doesn't have graceful handling for key types it
  doesn't recognize, it could cause an issue. With the included changes to
  opaque-keys, calling CourseKey.from_string(...) on these values will raise
  InvalidKeyError since they're not CourseKeys. (But calling
  LearningContextKey.from_string(...) will work for both course and library
  keys.)
* This commit introduces a slight regression for the Studio view of XBlocks in
  Blockstore content libraries: their state is now lost from request to request.
  I have a follow up PR to give them a proper studio-appropriate state store,
  but I want to review it separately so it doesn't hold up this PR and we can
  test this PR on its own.
2019-09-18 10:27:46 -04:00

118 lines
4.0 KiB
Python

"""
Django app configuration for the XBlock Runtime django app
"""
from __future__ import absolute_import, division, print_function, unicode_literals
from django.apps import AppConfig, apps
from django.conf import settings
from xblock.runtime import DictKeyValueStore, KvsFieldData
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.xblock.runtime.blockstore_field_data import BlockstoreFieldData
class XBlockAppConfig(AppConfig):
"""
Django app configuration for the new XBlock Runtime django app
"""
name = 'openedx.core.djangoapps.xblock'
verbose_name = 'New XBlock Runtime'
label = 'xblock_new' # The name 'xblock' is already taken by ORA2's 'openassessment.xblock' app :/
# If this is True, users must have 'edit' permission to be allowed even to
# view content. (It's only true in Studio)
require_edit_permission = False
def get_runtime_system_params(self):
"""
Get the XBlockRuntimeSystem parameters appropriate for viewing and/or
editing XBlock content.
"""
raise NotImplementedError
def get_site_root_url(self):
"""
Get the absolute root URL to this site, e.g. 'https://courses.example.com'
Should not have any trailing slash.
"""
raise NotImplementedError
def get_learning_context_params(self):
"""
Get additional kwargs that are passed to learning context implementations
(LearningContext subclass constructors). For example, this can be used to
specify that the course learning context should load the course's list of
blocks from the _draft_ version of the course in studio, but from the
published version of the course in the LMS.
"""
return {}
class LmsXBlockAppConfig(XBlockAppConfig):
"""
LMS-specific configuration of the XBlock Runtime django app.
"""
def get_runtime_system_params(self):
"""
Get the XBlockRuntimeSystem parameters appropriate for viewing and/or
editing XBlock content in the LMS
"""
return dict(
student_data_mode='persisted',
)
def get_site_root_url(self):
"""
Get the absolute root URL to this site, e.g. 'https://courses.example.com'
Should not have any trailing slash.
"""
return configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL)
class StudioXBlockAppConfig(XBlockAppConfig):
"""
Studio-specific configuration of the XBlock Runtime django app.
"""
# In Studio, users must have 'edit' permission to be allowed even to view content
require_edit_permission = True
BLOCKSTORE_DRAFT_NAME = "studio_draft"
def get_runtime_system_params(self):
"""
Get the XBlockRuntimeSystem parameters appropriate for viewing and/or
editing XBlock content in Studio
"""
return dict(
student_data_mode='ephemeral',
)
def get_site_root_url(self):
"""
Get the absolute root URL to this site, e.g. 'https://studio.example.com'
Should not have any trailing slash.
"""
scheme = "https" if settings.HTTPS == "on" else "http"
return scheme + '://' + settings.CMS_BASE
# or for the LMS version: configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL)
def get_learning_context_params(self):
"""
Get additional kwargs that are passed to learning context implementations
(LearningContext subclass constructors). For example, this can be used to
specify that the course learning context should load the course's list of
blocks from the _draft_ version of the course in studio, but from the
published version of the course in the LMS.
"""
return {
"use_draft": self.BLOCKSTORE_DRAFT_NAME,
}
def get_xblock_app_config():
"""
Get whichever of the above AppConfig subclasses is active.
"""
return apps.get_app_config(XBlockAppConfig.label)