Ejemplo n.º 1
0
    def __init__(self, vctx, location, page_desc):
        super(PageBaseWithTitle, self).__init__(vctx, location, page_desc)

        title = None
        try:
            title = self.page_desc.title
        except AttributeError:
            pass

        if title is None:
            try:
                md_body = self.markup_body_for_title()
            except NotImplementedError:
                from warnings import warn
                warn(
                    _("PageBaseWithTitle subclass '%s' does not implement "
                      "markdown_body_for_title()") % type(self).__name__)
            else:
                from course.content import extract_title_from_markup
                title = extract_title_from_markup(md_body)

        if title is None:
            raise ValidationError(
                string_concat("%s: ",
                              _("no title found in body or title attribute")) %
                (location))

        self._title = title
Ejemplo n.º 2
0
def validate_page_chunk(vctx, location, chunk):
    validate_struct(
            vctx,
            location,
            chunk,
            required_attrs=[
                ("id", str),
                ("content", "markup"),
                ],
            allowed_attrs=[
                ("title", str),
                ("rules", list),
                ]
            )

    title = getattr(chunk, "title", None)
    if title is None:
        from course.content import extract_title_from_markup
        title = extract_title_from_markup(chunk.content)

    if title is None:
        raise ValidationError(
                string_concat("%(location)s: ",
                    _("no title present"))
                % {'location': location})

    if hasattr(chunk, "rules"):
        for i, rule in enumerate(chunk.rules):
            validate_chunk_rule(vctx,
                    "%s, rule %d" % (location, i+1),
                    rule)
Ejemplo n.º 3
0
def validate_page_chunk(vctx, location, chunk):
    validate_struct(
            vctx,
            location,
            chunk,
            required_attrs=[
                ("id", str),
                ("content", "markup"),
                ],
            allowed_attrs=[
                ("title", str),
                ("rules", list),
                ]
            )

    title = getattr(chunk, "title", None)
    if title is None:
        from course.content import extract_title_from_markup
        title = extract_title_from_markup(chunk.content)

    if title is None:
        raise ValidationError(
                string_concat("%(location)s: ",
                    _("no title present"))
                % {'location': location})

    if hasattr(chunk, "rules"):
        for i, rule in enumerate(chunk.rules):
            validate_chunk_rule(vctx,
                    "%s, rule %d" % (location, i+1),
                    rule)
Ejemplo n.º 4
0
    def __init__(self, vctx, location, page_desc):
        super(PageBaseWithTitle, self).__init__(vctx, location, page_desc)

        title = None
        try:
            title = self.page_desc.title
        except AttributeError:
            pass

        if title is None:
            try:
                md_body = self.markup_body_for_title()
            except NotImplementedError:
                from warnings import warn
                warn(_("PageBaseWithTitle subclass '%s' does not implement "
                        "markdown_body_for_title()")
                        % type(self).__name__)
            else:
                from course.content import extract_title_from_markup
                title = extract_title_from_markup(md_body)

        if title is None:
            raise ValidationError(
                    string_concat(
                        "%s: ",
                        _("no title found in body or title attribute"))
                    % (location))

        self._title = title
Ejemplo n.º 5
0
def get_processed_page_chunks(course, repo, commit_sha,
        page_desc, role, now_datetime, facilities):
    for chunk in page_desc.chunks:
        chunk.weight, chunk.shown = \
                compute_chunk_weight_and_shown(
                        course, chunk, role, now_datetime,
                        facilities)
        chunk.html_content = markup_to_html(course, repo, commit_sha, chunk.content)
        if not hasattr(chunk, "title"):
            from course.content import extract_title_from_markup
            chunk.title = extract_title_from_markup(chunk.content)

    page_desc.chunks.sort(key=lambda chunk: chunk.weight, reverse=True)

    return [chunk for chunk in page_desc.chunks
            if chunk.shown]
Ejemplo n.º 6
0
def get_processed_page_chunks(course, repo, commit_sha, page_desc, role,
                              now_datetime, facilities):
    for chunk in page_desc.chunks:
        chunk.weight, chunk.shown = \
                compute_chunk_weight_and_shown(
                        course, chunk, role, now_datetime,
                        facilities)
        chunk.html_content = markup_to_html(course, repo, commit_sha,
                                            chunk.content)
        if not hasattr(chunk, "title"):
            from course.content import extract_title_from_markup
            chunk.title = extract_title_from_markup(chunk.content)

    page_desc.chunks.sort(key=lambda chunk: chunk.weight, reverse=True)

    return [chunk for chunk in page_desc.chunks if chunk.shown]
Ejemplo n.º 7
0
    def __init__(self, vctx, location, page_desc):
        super(PageBaseWithTitle, self).__init__(vctx, location, page_desc)

        title = None
        try:
            title = self.page_desc.title
        except AttributeError:
            pass

        if title is None:
            try:
                md_body = self.markup_body_for_title()
            except NotImplementedError:
                from warnings import warn
                warn(_("PageBaseWithTitle subclass '%s' does not implement "
                        "markup_body_for_title()")
                        % type(self).__name__)
            else:
                from course.content import extract_title_from_markup
                title = extract_title_from_markup(md_body)

        if title is None:
            raise ValidationError(
                    string_concat(
                        "%s: ",
                        _("no title found in body or title attribute"))
                    % (location))

        from markdown import markdown
        from django.utils.html import strip_tags
        title = strip_tags(markdown(title))

        if not title and vctx is not None:
            vctx.add_warning(location, _("the rendered title is an empty string"))

        self._title = title