Skip to content

levels

wdadaptivepy service for Adaptive's Levels.

LevelService

Create, retrieve, and modify Adaptive Levels.

Attributes:

Name Type Description
Level

wdadaptivepylevel

Source code in src/wdadaptivepy/services/levels.py
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
class LevelService:
    """Create, retrieve, and modify Adaptive Levels.

    Attributes:
        Level: wdadaptivepylevel

    """

    def __init__(self, xml_api: XMLApi) -> None:
        """Initialize LevelService.

        Args:
            xml_api: wdadaptivepy XMLApi

        """
        self.__xml_api = xml_api
        self.Level = Level

    def get_all(self, *, display_name_enabled: bool = True) -> MetadataList[Level]:
        """Retrieve all Levels from Adaptive.

        Args:
            display_name_enabled: Adaptive Display Name Enabled

        Returns:
            adaptive Levels

        """
        include = ET.Element(
            "include",
            attrib={
                "displayNameEnabled": str(bool_to_str_true_false(display_name_enabled)),
            },
        )

        response = self.__xml_api.make_xml_request(
            method="exportLevels",
            payload=include,
        )
        return MetadataList[Level](Level.from_xml(xml=response))

    def preview_update(
        self,
        levels: Sequence[Level],
        *,
        hide_password: bool = True,
    ) -> ET.Element:
        """Generate Level update XML API call for review.

        Args:
            levels: wdadaptivepy Levels to update
            hide_password: Prevent password from being displayed

        Returns:
            XML API body

        """
        updated_levels = Level.to_xml("update", levels)
        # ET.indent(updated_levels)
        # with open("test_levels.xml", "w", encoding="utf-8") as fp:
        #     fp.write(ET.tostring(updated_levels, encoding="unicode"))
        return self.__xml_api.preview_xml_request(
            method="importLevels",
            payload=updated_levels,
            hide_password=hide_password,
        )

    def from_json(self, data: str) -> MetadataList[Level]:
        """Convert JSON to MetadataList of Levels.

        Args:
            data: JSON string

        Returns:
            MetadataList of Levels

        """
        return MetadataList[Level](Level.from_json(data=data))

    def from_dict(self, data: Sequence[dict] | dict) -> MetadataList[Level]:
        """Convert Python Dictionary to MetadataList of Levels.

        Args:
            data: Python Dictionary

        Returns:
            MetadataList of Levels

        """
        return MetadataList[Level](Level.from_dict(data=data))

__init__(xml_api)

Initialize LevelService.

Parameters:

Name Type Description Default
xml_api XMLApi

wdadaptivepy XMLApi

required
Source code in src/wdadaptivepy/services/levels.py
20
21
22
23
24
25
26
27
28
def __init__(self, xml_api: XMLApi) -> None:
    """Initialize LevelService.

    Args:
        xml_api: wdadaptivepy XMLApi

    """
    self.__xml_api = xml_api
    self.Level = Level

from_dict(data)

Convert Python Dictionary to MetadataList of Levels.

Parameters:

Name Type Description Default
data Sequence[dict] | dict

Python Dictionary

required

Returns:

Type Description
MetadataList[Level]

MetadataList of Levels

Source code in src/wdadaptivepy/services/levels.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def from_dict(self, data: Sequence[dict] | dict) -> MetadataList[Level]:
    """Convert Python Dictionary to MetadataList of Levels.

    Args:
        data: Python Dictionary

    Returns:
        MetadataList of Levels

    """
    return MetadataList[Level](Level.from_dict(data=data))

from_json(data)

Convert JSON to MetadataList of Levels.

Parameters:

Name Type Description Default
data str

JSON string

required

Returns:

Type Description
MetadataList[Level]

MetadataList of Levels

Source code in src/wdadaptivepy/services/levels.py
79
80
81
82
83
84
85
86
87
88
89
def from_json(self, data: str) -> MetadataList[Level]:
    """Convert JSON to MetadataList of Levels.

    Args:
        data: JSON string

    Returns:
        MetadataList of Levels

    """
    return MetadataList[Level](Level.from_json(data=data))

get_all(*, display_name_enabled=True)

Retrieve all Levels from Adaptive.

Parameters:

Name Type Description Default
display_name_enabled bool

Adaptive Display Name Enabled

True

Returns:

Type Description
MetadataList[Level]

adaptive Levels

Source code in src/wdadaptivepy/services/levels.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def get_all(self, *, display_name_enabled: bool = True) -> MetadataList[Level]:
    """Retrieve all Levels from Adaptive.

    Args:
        display_name_enabled: Adaptive Display Name Enabled

    Returns:
        adaptive Levels

    """
    include = ET.Element(
        "include",
        attrib={
            "displayNameEnabled": str(bool_to_str_true_false(display_name_enabled)),
        },
    )

    response = self.__xml_api.make_xml_request(
        method="exportLevels",
        payload=include,
    )
    return MetadataList[Level](Level.from_xml(xml=response))

preview_update(levels, *, hide_password=True)

Generate Level update XML API call for review.

Parameters:

Name Type Description Default
levels Sequence[Level]

wdadaptivepy Levels to update

required
hide_password bool

Prevent password from being displayed

True

Returns:

Type Description
Element

XML API body

Source code in src/wdadaptivepy/services/levels.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def preview_update(
    self,
    levels: Sequence[Level],
    *,
    hide_password: bool = True,
) -> ET.Element:
    """Generate Level update XML API call for review.

    Args:
        levels: wdadaptivepy Levels to update
        hide_password: Prevent password from being displayed

    Returns:
        XML API body

    """
    updated_levels = Level.to_xml("update", levels)
    # ET.indent(updated_levels)
    # with open("test_levels.xml", "w", encoding="utf-8") as fp:
    #     fp.write(ET.tostring(updated_levels, encoding="unicode"))
    return self.__xml_api.preview_xml_request(
        method="importLevels",
        payload=updated_levels,
        hide_password=hide_password,
    )