def render_sphinx_page(course: str, docname: str): build = syllabus.get_sphinx_build(course) if docname.endswith(".html"): doc_path = safe_join(build.builder.outdir, docname) config = syllabus.get_config() inginious_config = config['courses'][course]['inginious'] inginious_course_url = "%s/%s" % (inginious_config['url'], inginious_config['course_id']) path = safe_join(inginious_config.get("simple_grader_pattern", "/"), inginious_config['course_id']) inginious_sandbox_url = urllib.parse.urljoin(inginious_config["url"], path) same_origin_proxy = inginious_config['same_origin_proxy'] try: with open(doc_path) as f: store_last_visited() return render_template_string('{{% extends "sphinx_page.html" %}} {{% block content %}}{}{{% endblock %}}'.format(f.read()), logged_in=session.get("user", None), inginious_course_url=inginious_course_url if not same_origin_proxy else ( "/postinginious/" + course), inginious_sandbox_url=inginious_sandbox_url, courses_titles={course: config["courses"][course]["title"] for course in syllabus.get_courses()}, inginious_config=inginious_config, inginious_url=inginious_config['url'], course_str=course, get_lti_data=get_lti_data, get_lti_submission=get_lti_submission, login_img="/static/login.png" if config['courses'][course].get("use_logged_out_img", False) else None) except FileNotFoundError: abort(404) return send_from_directory(build.builder.outdir, docname)
def render_web_page(course: str, content: Content, print_mode=False, display_print_all=False): try: TOC = syllabus.get_toc(course) session["print_mode"] = print_mode try: previous = TOC.get_previous_content(content) except KeyError: previous = None try: next = TOC.get_next_content(content) except KeyError: next = None config = syllabus.get_config() inginious_config = config['courses'][course]['inginious'] inginious_course_url = "%s/%s" % (inginious_config['url'], inginious_config['course_id']) same_origin_proxy = inginious_config['same_origin_proxy'] retval = render_template( 'rst_page.html' if not print_mode else 'print_page.html', logged_in=session.get("user", None), inginious_course_url=inginious_course_url if not same_origin_proxy else ("/postinginious/" + course), inginious_url=inginious_config['url'], containing_chapters=TOC.get_containing_chapters_of(content), this_content=content, render_rst=lambda content, **kwargs: syllabus.utils.pages. render_content(course, content, **kwargs), content_at_same_level=TOC.get_content_at_same_level(content), course_str=course, courses_titles={ course: config["courses"][course]["title"] for course in syllabus.get_courses() }, toc=TOC, direct_content=TOC.get_direct_content_of(content), next=next, previous=previous, display_print_all=display_print_all, get_lti_data=get_lti_data, get_lti_submission=get_lti_submission) session["print_mode"] = False except Exception: # ensure that the print mode is disabled session["print_mode"] = False raise return retval
def render_web_page(course: str, content: Content, print_mode=False, display_print_all=False): try: TOC = syllabus.get_toc(course) session["print_mode"] = print_mode try: previous = TOC.get_previous_content(content) except KeyError: previous = None try: next = TOC.get_next_content(content) except KeyError: next = None config = syllabus.get_config() inginious_config = config['courses'][course]['inginious'] inginious_course_url = "%s/%s" % (inginious_config['url'], inginious_config['course_id']) path = safe_join(inginious_config.get("simple_grader_pattern", "/"), inginious_config['course_id']) inginious_sandbox_url = urllib.parse.urljoin(inginious_config["url"], path) same_origin_proxy = inginious_config['same_origin_proxy'] retval = render_template('rst_page.html' if not print_mode else 'print_page.html', logged_in=session.get("user", None), inginious_config = syllabus.get_config()['courses'][course]['inginious'], inginious_course_url=inginious_course_url if not same_origin_proxy else ("/postinginious/" + course), inginious_sandbox_url=inginious_sandbox_url, inginious_url=inginious_config['url'], containing_chapters=TOC.get_containing_chapters_of(content), this_content=content, render_rst=lambda content, **kwargs: syllabus.utils.pages.render_content(course, content, **kwargs), render_footer= lambda course: syllabus.utils.pages.render_footer(course), content_at_same_level=TOC.get_content_at_same_level(content), course_str=course, courses_titles={course: config["courses"][course]["title"] for course in syllabus.get_courses()}, toc=TOC, direct_content=TOC.get_direct_content_of(content), next=next, previous=previous, display_print_all=display_print_all, get_lti_data=get_lti_data, get_lti_submission=get_lti_submission, render_rst_str=syllabus.utils.pages.render_rst_str, login_img="/static/login.png" if os.path.exists(os.path.join(app.static_folder, "login.png")) else None, auth_methods=syllabus.get_config()["authentication_methods"]) session["print_mode"] = False except Exception: # ensure that the print mode is disabled session["print_mode"] = False raise return retval
def refresh(course): TOC = syllabus.get_toc(course) data = request.form['content'] config = syllabus.get_config() inginious_config = config['courses'][course]['inginious'] inginious_course_url = "%s/%s" % (inginious_config['url'], inginious_config['course_id']) path = safe_join(inginious_config.get("simple_grader_pattern", "/"), inginious_config['course_id']) inginious_sandbox_url = urllib.parse.urljoin(inginious_config["url"], path) same_origin_proxy = inginious_config['same_origin_proxy'] code_html = render_template_string(publish_string(data, writer_name='html', settings_overrides=default_rst_opts), logged_in=session.get("user", None), inginious_sandbox_url=inginious_sandbox_url, inginious_course_url=inginious_course_url if not same_origin_proxy else ("/postinginious/" + course), inginious_url=inginious_config['url'], this_content=data, render_rst=lambda content, **kwargs: syllabus.utils.pages.render_content(course, content, **kwargs), course_str=course, courses_titles={course: config["courses"][course]["title"] for course in syllabus.get_courses()}, toc=TOC, get_lti_data=get_lti_data, get_lti_submission=get_lti_submission, render_rst_str=syllabus.utils.pages.render_rst_str) return "<div id=\"preview\" style=\"overflow-y: scroll\">"+code_html+"</div>"
def config_edition(): if request.method == "POST": inpt = request.form if "new_config" in inpt: try: # check YAML validity config = yaml.load(inpt["new_config"]) # TODO: check that the configuration has the appropriate fields # update the config old_config = syllabus.get_config() syllabus.set_config(inpt["new_config"]) # sync the git repo if it has changed try: courses = set( list(old_config["courses"].keys()) + list(config["courses"].keys())) for course in courses: old_pages_config = old_config["courses"].get( course, {}).get("pages", {}) pages_config = config["courses"].get(course, {}).get( "pages", {}) if ( "git" not in old_pages_config and "git" in pages_config ) or old_pages_config["git"] != pages_config["git"]: syllabus.utils.pages.init_and_sync_repo( course, force_sync=True) except KeyError as e: pass except AttributeError: return seeother( request.path, Feedback(feedback_type="error", message="The git repository has " "failed to synchronize. " "Please check your " "configuration.")) return seeother( request.path, Feedback(feedback_type="success", message="The table of contents has been" " modified successfully !")) except yaml.YAMLError: return seeother( request.path, feedback=Feedback( feedback_type="error", message="The submitted configuration is not " "written in valid YAML.")) else: params = Params.query.one() config = syllabus.get_config() hook_paths = [ ("/update_pages/{}/{}".format(params.git_hook_url, course)) if "git" in config["courses"][course]["pages"] and params.git_hook_url is not None else None for course in syllabus.get_courses() ] try: with open(syllabus.get_config_path(), 'r') as f: return render_template( 'edit_configuration.html', active_element=sidebar['active_element'], sidebar_elements=sidebar['elements'], config=f.read(), hook_paths=hook_paths, feedback=pop_feeback(session)) except TemplateNotFound: abort(404)
from syllabus.utils.yaml_ordered_dict import OrderedDictYAMLLoader import syllabus from flask import Blueprint, render_template, abort, request, session from jinja2 import TemplateNotFound from syllabus.models.user import User from syllabus.utils.pages import permission_admin, seeother admin_blueprint = Blueprint('admin', __name__, template_folder='templates', static_folder='static') sidebar_elements = [{'id': 'users', 'name': 'Users', 'icon': 'users'}] + \ [{'id': 'content_edition/' + course, 'name': 'Content Edition ' + course, 'icon': 'edit'} for course in syllabus.get_courses()] + \ [{'id': 'toc_edition/' + course, 'name': 'ToC Edition ' + course, 'icon': 'list'} for course in syllabus.get_courses()] + \ [{'id': 'config_edition', 'name': 'Configuration Edition', 'icon': 'cog'}] sidebar = {'active_element': 'users', 'elements': sidebar_elements} def sidebar_page(element): def decorator(f): @wraps(f) def wrapper(*args, **kwargs): sidebar['active_element'] = element return f(*args, **kwargs) return wrapper