def aplus_json(request, course_key): ''' Delivers the configuration as JSON for A+. ''' course = config.course_entry(course_key) if course is None: raise Http404() data = _copy_fields(course, ["name", "description", "lang", "contact", "assistants", "start", "end", "categories", "numerate_ignoring_modules"]) def children_recursion(parent): if not "children" in parent: return [] result = [] for o in [o for o in parent["children"] if "key" in o]: of = _type_dict(o, course.get("exercise_types", {})) if "config" in of: _, exercise = config.exercise_entry(course["key"], of["key"]) of = export.exercise(request, course, exercise, of) elif "static_content" in of: of = export.chapter(request, course, of) of["children"] = children_recursion(o) result.append(of) return result modules = [] if "modules" in course: for m in course["modules"]: mf = _type_dict(m, course.get("module_types", {})) mf["children"] = children_recursion(m) modules.append(mf) data["modules"] = modules return JsonResponse(data)
def aplus_json(request, course_key): ''' Delivers the configuration as JSON for A+. ''' course = config.course_entry(course_key) if course is None: raise Http404() data = _copy_fields(course, [ "archive_time", "assistants", "categories", "contact", "content_numbering", "course_description", "course_footer", "description", "end", "enrollment_audience", "enrollment_end", "enrollment_start", "head_urls", "index_mode", "lang", "lifesupport_time", "module_numbering", "name", "numerate_ignoring_modules", "start", "view_content_to", ]) if "language" in course: data["lang"] = course["language"] def children_recursion(parent): if not "children" in parent: return [] result = [] for o in [o for o in parent["children"] if "key" in o]: of = _type_dict(o, course.get("exercise_types", {})) if "config" in of: _, exercise = config.exercise_entry(course["key"], str(of["key"]), '_root') of = export.exercise(request, course, exercise, of) elif "static_content" in of: of = export.chapter(request, course, of) of["children"] = children_recursion(o) result.append(of) return result modules = [] if "modules" in course: for m in course["modules"]: mf = _type_dict(m, course.get("module_types", {})) mf["children"] = children_recursion(m) modules.append(mf) data["modules"] = modules if "gitmanager" in settings.INSTALLED_APPS: data["build_log_url"] = request.build_absolute_uri(reverse("build-log-json", args=(course_key, ))) return JsonResponse(data)
def aplus_json(request, course_key): ''' Delivers the configuration as JSON for A+. ''' course = config.course_entry(course_key) if course is None: raise Http404() data = _copy_fields(course, ["name", "description", "lang", "contact", "assistants", "start", "end", "categories", "numerate_ignoring_modules"]) if "language" in course: data["lang"] = course["language"] def children_recursion(parent): if not "children" in parent: return [] result = [] for o in [o for o in parent["children"] if "key" in o]: of = _type_dict(o, course.get("exercise_types", {})) if "config" in of: _, exercise = config.exercise_entry(course["key"], str(of["key"]), '_root') of = export.exercise(request, course, exercise, of) elif "static_content" in of: of = export.chapter(request, course, of) of["children"] = children_recursion(o) result.append(of) return result modules = [] if "modules" in course: for m in course["modules"]: mf = _type_dict(m, course.get("module_types", {})) mf["children"] = children_recursion(m) modules.append(mf) data["modules"] = modules if "gitmanager" in settings.INSTALLED_APPS: data["build_log_url"] = request.build_absolute_uri(reverse("build-log-json", args=(course_key, ))) return JsonResponse(data)
def aplus_json(request: HttpRequest, course_key: str) -> JsonResponse: ''' Delivers the configuration as JSON for A+. ''' SecurityLog.accept(request, "APLUS-JSON", f"course_id={course_key}") try: course = config.course_entry(course_key) except ConfigError as e: return _error_response(exc=e) if course is None: raise Http404() data = _copy_fields(course, [ "archive_time", "assistants", "categories", "contact", "content_numbering", "course_description", "course_footer", "description", "end", "enrollment_audience", "enrollment_end", "enrollment_start", "head_urls", "index_mode", "lang", "lifesupport_time", "module_numbering", "name", "numerate_ignoring_modules", "start", "view_content_to", ]) errors = [] def children_recursion(parent): if not "children" in parent: return [] result = [] for o in [o for o in parent["children"] if "key" in o]: of = _type_dict(o, course.get("exercise_types", {})) if "config" in of: try: _, exercise = config.exercise_entry( course["key"], str(of["key"]), '_root') except ConfigError as e: errors.append(str(e)) continue of = export.exercise(request, course, exercise, of) elif "static_content" in of: of = export.chapter(request, course, of) of["children"] = children_recursion(o) result.append(of) return result modules = [] if "modules" in course: for m in course["modules"]: mf = _type_dict(m, course.get("module_types", {})) mf["children"] = children_recursion(m) modules.append(mf) data["modules"] = modules if errors: data["errors"] = errors return JsonResponse(data)