def course(course): if course.is_link(): naucse.utils.views.forks_raise_if_disabled() try: data_from_fork = course.render_course(request_url=request.path) edit_info = links.process_edit_info( data_from_fork.get("edit_info")) content = data_from_fork.get("content") if content is None: raise InvalidInfo("Content of the page can't be None.") except POSSIBLE_FORK_EXCEPTIONS as e: if raise_errors_from_forks(): raise # there's no way to replace this page, render an error page instead logger.error("There was an error rendering url %s for course '%s'", request.path, course.slug) logger.exception(e) return render_template( "error_in_fork.html", malfunctioning_course=course, edit_info=get_edit_info(course.edit_path), faulty_page="course", root_slug=model.meta.slug, travis_build_id=os.environ.get("TRAVIS_BUILD_ID"), ) record_content_urls(data_from_fork, f"/{course.slug}/") kwargs = { "course_content": content, "edit_info": edit_info, } else: content = course_content(course) allowed_elements_parser.reset_and_feed(content) kwargs = { "course_content": content, "edit_info": get_edit_info(course.edit_path), } recent_runs = get_recent_runs(course) try: return render_template("course.html", course=course, title=course.title, recent_runs=recent_runs, **kwargs) except TemplateNotFound: abort(404)
def course_calendar(course): if course.is_link(): naucse.utils.views.forks_raise_if_disabled() try: data_from_fork = course.render_calendar(request_url=request.path) record_content_urls(data_from_fork, f"/{course.slug}/") course = process_course_data(data_from_fork.get("course"), slug=course.slug) edit_info = links.process_edit_info( data_from_fork.get("edit_info")) content = data_from_fork.get("content") if content is None: raise InvalidInfo("Content of the page can't be None.") except POSSIBLE_FORK_EXCEPTIONS as e: if raise_errors_from_forks(): raise logger.error("There was an error rendering url %s for course '%s'", request.path, course.slug) logger.exception(e) return render_template( "error_in_fork.html", malfunctioning_course=course, edit_info=get_edit_info(course.edit_path), faulty_page="calendar", root_slug=model.meta.slug, travis_build_id=os.environ.get("TRAVIS_BUILD_ID"), ) kwargs = {"course": course, "edit_info": edit_info, "content": content} else: if not course.start_date: abort(404) content = course_calendar_content(course) allowed_elements_parser.reset_and_feed(content) kwargs = { "course": course, "edit_info": get_edit_info(course.edit_path), "content": content } return render_template('course_calendar.html', **kwargs)
def course_calendar_ics(course): if not course.start_date: abort(404) if course.is_link(): naucse.utils.views.forks_raise_if_disabled() try: data_from_fork = course.render_calendar_ics( request_url=request.path) record_content_urls(data_from_fork, f"/{course.slug}/") calendar = data_from_fork.get("calendar") if calendar is None: raise InvalidInfo("The calendar can't be None.") except POSSIBLE_FORK_EXCEPTIONS as e: if raise_errors_from_forks(): raise logger.error("There was an error rendering url %s for course '%s'", request.path, course.slug) logger.exception(e) error_html = render_template( "error_in_fork.html", malfunctioning_course=course, edit_info=get_edit_info(course.edit_path), faulty_page="calendar", root_slug=model.meta.slug, travis_build_id=os.environ.get("TRAVIS_BUILD_ID"), ) # XXX: Hack for static site generation -- the .ics extension # means the error page is served as text/calendar. There's # no good way to make an actual calendar show an error. # https://github.com/pyvec/naucse.python.cz/issues/424 return Response(error_html, mimetype="text/calendar") else: try: calendar = generate_calendar_ics(course) except ValueError: abort(404) return Response(str(calendar), mimetype="text/calendar")
def course_calendar_ics(course): if not course.start_date: abort(404) if course.is_link(): naucse.utils.views.forks_raise_if_disabled() try: data_from_fork = course.render_calendar_ics( request_url=request.path) record_content_urls(data_from_fork, f"/{course.slug}/") calendar = data_from_fork.get("calendar") if calendar is None: raise InvalidInfo("The calendar can't be None.") except POSSIBLE_FORK_EXCEPTIONS as e: if raise_errors_from_forks(): raise logger.error("There was an error rendering url %s for course '%s'", request.path, course.slug) logger.exception(e) return render_template( "error_in_fork.html", malfunctioning_course=course, edit_info=get_edit_info(course.edit_path), faulty_page="calendar", root_slug=model.meta.slug, travis_build_id=os.environ.get("TRAVIS_BUILD_ID"), ) else: try: calendar = generate_calendar_ics(course) except ValueError: abort(404) return Response(str(calendar), mimetype="text/calendar")
def session_coverpage(course, session, coverpage): """Render the session coverpage. Args: course course where the session belongs session name of the session coverpage coverpage of the session, front is default Returns: rendered session coverpage """ if course.is_link(): naucse.utils.views.forks_raise_if_disabled() try: data_from_fork = course.render_session_coverpage( session, coverpage, request_url=request.path) record_content_urls(data_from_fork, f"/{course.slug}/") content = data_from_fork.get("content") if content is None: raise InvalidInfo("Content of the page can't be None.") kwargs = { "course": process_course_data(data_from_fork.get("course"), slug=course.slug), "session": process_session_data(data_from_fork.get("session"), slug=session), "edit_info": links.process_edit_info(data_from_fork.get("edit_info")), "content": content } except POSSIBLE_FORK_EXCEPTIONS as e: if raise_errors_from_forks(): raise # there's no way to replace this page, render an error page instead logger.error("There was an error rendering url %s for course '%s'", request.path, course.slug) logger.exception(e) return render_template( "error_in_fork.html", malfunctioning_course=course, edit_info=get_edit_info(course.edit_path), faulty_page=f"session_{coverpage}", session=session, root_slug=model.meta.slug, travis_build_id=os.environ.get("TRAVIS_BUILD_ID"), ) else: session = course.sessions.get(session) content = session_coverpage_content(course, session, coverpage) allowed_elements_parser.reset_and_feed(content) kwargs = { "course": course, "session": session, "edit_info": get_edit_info(session.get_edit_path(course, coverpage)), "content": content } return render_template("coverpage.html", **kwargs)