Section¶
py_moodle.section ¶
Section management module for Moodle CLI.
Provides functions to list, create, and delete course sections using AJAX endpoints.
All code and comments must be in English.
Classes:
Name | Description |
---|---|
MoodleSectionError |
Exception raised for errors in section operations. |
Functions:
Name | Description |
---|---|
list_sections |
List all sections and modules for a given course using core_courseformat_get_state. |
create_section |
Create a new section in a course. |
delete_section |
Delete a section from a course. |
Classes¶
MoodleSectionError ¶
Bases: Exception
Exception raised for errors in section operations.
Functions¶
list_sections ¶
List all sections and modules for a given course using core_courseformat_get_state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Authenticated requests.Session object. |
required |
base_url
|
str
|
Base URL of the Moodle instance. |
required |
sesskey
|
str
|
Session key for AJAX calls. |
required |
courseid
|
int
|
ID of the course. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dictionary with keys: 'course', 'section', 'cm' (modules). |
Raises:
Type | Description |
---|---|
MoodleSectionError
|
If the request fails. |
create_section ¶
Create a new section in a course.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Authenticated requests.Session object. |
required |
base_url
|
str
|
Base URL of the Moodle instance. |
required |
sesskey
|
str
|
Session key for AJAX calls. |
required |
courseid
|
int
|
ID of the course. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
The last created section as a dictionary. |
Raises:
Type | Description |
---|---|
MoodleSectionError
|
If the request fails. |
delete_section ¶
delete_section(
session: Session,
base_url: str,
sesskey: str,
courseid: int,
sectionid: int,
) -> Dict[str, Any]
Delete a section from a course.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Authenticated requests.Session object. |
required |
base_url
|
str
|
Base URL of the Moodle instance. |
required |
sesskey
|
str
|
Session key for AJAX calls. |
required |
courseid
|
int
|
ID of the course. |
required |
sectionid
|
int
|
ID of the section to delete. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
The response dictionary from Moodle. |
Raises:
Type | Description |
---|---|
MoodleSectionError
|
If the request fails. |