in microservices/learning_object_service/src/routes/curriculum_pathway.py [0:0]
def fetch_child_nodes_with_filters(uuid: str,
level: str,
node_type: str,
alias: Optional[str] = None,
type: Optional[str] = None, #pylint: disable=redefined-builtin
is_autogradable: Optional[bool] = None):
"""
This endpoint fetches all nodes belonging to the given alias eg. discipline.
Parameters:
level (str) - level of the node, below which all nodes of type
node_type will be fetched. level have the following values:
Literal[curriculum-pathways, learning-experiences, learning-objects,
learning-resources, assessments]
uuid: (str) - uuid of the node of type level
node_type(str) - All nodes of type node_type will be fetched
which occur below the node of type level.
node_type can the following values:
Literal[curriculum-pathways, learning-experiences, learning-objects,
learning-resources, assessments, competencies, skills]
alias(str) - All nodes of type node_type that are fetched can be
filtered on alias field, if the node has alias as field, otherwise it
will throw ValidationError.
This filter is applicable for the following node_types:
Literal[curriculum-pathways, learning-experiences, learning-objects,
learning-resources, assessments]
Here, is the list of aliases that can be used for the node_types:
curriculum-pathways: Literal["program", "level", "discipline", "unit"]
learning-experiences: Literal[learning_experience]
learning-objects: Literal["module"]
learning-resources: Literal["lesson"]
assessments: Literal["assessment"]
type(str) - All nodes of type node_type that are fetched can be filtered
on type field, if the node has type as field, otherwise it will throw
ValidationError.
This filter is applicable for the following node_types:
Literal[curriculum-pathways, learning-experiences, learning-objects,
learning-resources, assessments]
Here, is the list of types that can be used for the node_types:
curriculum-pathways: Literal["pathway"]
learning-experiences: Literal[learning_experience]
learning-objects: Literal["srl", "static_srl", "cognitive_wrapper",
"pretest", "learning_module", "unit_overview", "project"]
learning-resources: Literal["pdf", "image", "html_package", "html",
"video", "scorm", "docx",""]
assessments: Literal["practice", "project", "pretest", "srl", "static_srl",
"cognitive_wrapper"]
is_autogradable(bool) - Filter applicable on nodes of type assessments.
If given False or True will filter out only human-gradable or
autogradable assessments. If None, it will give list of all assessments.
Raises:
ResourceNotFoundException: If the program (pathway) does not exist.
Exception 500: Internal Server Error. Raised if something went wrong
Returns:
List of nodes of alias type
"""
try:
response = []
node_type = node_type.replace("-", "_")
level = level.replace("-", "_")
if node_type in SKILL_NODES:
if alias is not None or type is not None or is_autogradable is not None:
raise ValidationError(f"{node_type} does not have alias, type or "
"is_autogradable fields as part of the Schema")
if node_type in LOS_NODES:
if alias and alias not in LOS_LITERALS[node_type]["alias"]:
raise ValidationError(f"{node_type} can have the following aliases: "
f"""{LOS_LITERALS[node_type]["alias"]}""")
if type and type not in LOS_LITERALS[node_type]["type"]:
raise ValidationError(f"{node_type} can have the following types: "
f"""{LOS_LITERALS[node_type]["type"]}""")
if is_autogradable is not None and node_type != "assessments":
raise ValidationError("is_autogradable field is not supported by "
f"{node_type} data model")
nodes = get_all_nodes(uuid, level, node_type, [])
if nodes is None:
raise ValidationError(("Could not find any nodes of type "
f"{node_type} from {uuid}."
" Please use different uuid or alias."))
else:
# If block to handle filters on the fetched nodes of type node_type
if alias is not None:
nodes = [node for node in nodes if node["alias"]==alias]
if type is not None:
nodes = [node for node in nodes if node["type"]==type]
if is_autogradable is not None:
nodes = [node for node in nodes if node[
"is_autogradable"]==is_autogradable]
for node in nodes:
response.append(
{
"uuid": node["uuid"],
"collection": node_type,
"name": node["name"],
"description": node.get("description", ""),
"alias": node.get("alias", None),
"type": node.get("type", None),
"is_autogradable": node.get("is_autogradable", None),
}
)
# Remove duplicates from list of responses
response = [dict(t) for t in {tuple(d.items()) for d in response}]
return {
"success": True,
"message": "Data fetched successfully",
"data": response
}
except ValidationError as e:
Logger.error(e)
Logger.error(traceback.print_exc())
raise BadRequest(str(e)) from e
except ResourceNotFoundException as e:
Logger.error(e)
Logger.error(traceback.print_exc())
raise ResourceNotFound(str(e)) from e
except Exception as e:
Logger.error(e)
Logger.error(traceback.print_exc())
raise InternalServerError(str(e)) from e