field_data.py 1.26 KB
Newer Older
Calen Pennington committed
1 2 3 4 5 6 7 8
"""
:class:`~xblock.field_data.FieldData` subclasses used by the LMS
"""

from xblock.field_data import ReadOnlyFieldData, SplitFieldData
from xblock.fields import Scope


9
class LmsFieldData(SplitFieldData):
Calen Pennington committed
10
    """
11
    A :class:`~xblock.field_data.FieldData` that
Calen Pennington committed
12 13 14 15
    reads all UserScope.ONE and UserScope.ALL fields from `student_data`
    and all UserScope.NONE fields from `authored_data`. It also prevents
    writing to `authored_data`.
    """
16 17 18
    def __init__(self, authored_data, student_data):
        # Make sure that we don't repeatedly nest LmsFieldData instances
        if isinstance(authored_data, LmsFieldData):
19
            authored_data = authored_data._authored_data  # pylint: disable=protected-member
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
        else:
            authored_data = ReadOnlyFieldData(authored_data)

        self._authored_data = authored_data
        self._student_data = student_data

        super(LmsFieldData, self).__init__({
            Scope.content: authored_data,
            Scope.settings: authored_data,
            Scope.parent: authored_data,
            Scope.children: authored_data,
            Scope.user_state_summary: student_data,
            Scope.user_state: student_data,
            Scope.user_info: student_data,
            Scope.preferences: student_data,
        })