api.py 2.28 KB
Newer Older
1 2 3
"""
API methods related to xblock state.
"""
4 5

from xblock_django.models import XBlockConfiguration, XBlockStudioConfiguration
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25


def deprecated_xblocks():
    """
    Return the QuerySet of deprecated XBlock types. Note that this method is independent of
    `XBlockStudioConfigurationFlag` and `XBlockStudioConfiguration`.
    """
    return XBlockConfiguration.objects.current_set().filter(deprecated=True)


def disabled_xblocks():
    """
    Return the QuerySet of disabled XBlock types (which should not render in the LMS).
    Note that this method is independent of `XBlockStudioConfigurationFlag` and `XBlockStudioConfiguration`.
    """
    return XBlockConfiguration.objects.current_set().filter(enabled=False)


def authorable_xblocks(allow_unsupported=False, name=None):
    """
26 27 28 29 30
    This method returns the QuerySet of XBlocks that can be created in Studio (by default, only fully supported
    and provisionally supported XBlocks), as stored in `XBlockStudioConfiguration`.
    Note that this method does NOT check the value `XBlockStudioConfigurationFlag`, nor does it take into account
    fully disabled xblocks (as returned by `disabled_xblocks`) or deprecated xblocks
    (as returned by `deprecated_xblocks`).
31 32 33 34 35 36 37 38 39

    Arguments:
        allow_unsupported (bool): If `True`, enabled but unsupported XBlocks will also be returned.
            Note that unsupported XBlocks are not recommended for use in courses due to non-compliance
            with one or more of the base requirements, such as testing, accessibility, internationalization,
            and documentation. Default value is `False`.
        name (str): If provided, filters the returned XBlocks to those with the provided name. This is
            useful for XBlocks with lots of template types.
    Returns:
40 41 42
        QuerySet: Returns authorable XBlocks, taking into account `support_level`, `enabled` and `name`
        (if specified) as specified by `XBlockStudioConfiguration`. Does not take into account whether or not
        `XBlockStudioConfigurationFlag` is enabled.
43 44 45 46 47 48 49 50 51
    """
    blocks = XBlockStudioConfiguration.objects.current_set().filter(enabled=True)
    if not allow_unsupported:
        blocks = blocks.exclude(support_level=XBlockStudioConfiguration.UNSUPPORTED)

    if name:
        blocks = blocks.filter(name=name)

    return blocks