def render(self, page_type, *args, **kwargs): """ Renders a page in the fork, checks the content and registers urls to freeze. """ naucse.utils.routes.forks_raise_if_disabled() task = Task( "naucse.utils.forks:render", args=[page_type, self.slug] + list(args), kwargs=kwargs, ) result = arca.run(self.repo, self.branch, task, reference=Path("."), depth=None) if page_type != "calendar_ics" and result.output["content"] is not None: allowed_elements_parser.reset_and_feed(result.output["content"]) if "urls" in result.output: # freeze urls generated by the code in fork, but only if they start with the slug of the course absolute_urls_to_freeze.extend([ url for url in result.output["urls"] if url.startswith(f"/{self.slug}/") ]) return result.output
def get_footer_links(self, lesson_slug, page, **kwargs): """Return links to previous page, current session and the next page. Each link is either a dict with 'url' and 'title' keys or ``None``. If :meth:`render_page` fails and a canonical version is in the base repo, it's used instead with a warning. This method provides the correct footer links for the page, since ``sessions`` is not included in the info provided by forks. """ naucse.utils.views.forks_raise_if_disabled() task = Task("naucse.utils.forks:get_footer_links", args=[self.slug, lesson_slug, page], kwargs=kwargs) result = arca.run(self.repo, self.branch, task, reference=Path("."), depth=None) to_return = [] from naucse.views import logger logger.debug(result.output) if not isinstance(result.output, dict): return None, None, None def validate_link(link, key): return key in link and isinstance(link[key], str) for link_type in "prev_link", "session_link", "next_link": link = result.output.get(link_type) if isinstance(link, dict) and validate_link( link, "url") and validate_link(link, "title"): if link["url"].startswith(f"/{self.slug}/"): absolute_urls_to_freeze.append(link["url"]) to_return.append(link) else: to_return.append(None) logger.debug(to_return) return to_return
def render(self, page_type, *args, **kwargs): """Render a page in the fork. Check the content and registers URLs to freeze. """ naucse.utils.views.forks_raise_if_disabled() task = Task( "naucse.utils.forks:render", args=[page_type, self.slug] + list(args), kwargs=kwargs, ) result = arca.run(self.repo, self.branch, task, reference=Path("."), depth=None) if page_type != "calendar_ics" and result.output["content"] is not None: allowed_elements_parser.reset_and_feed(result.output["content"]) return result.output