Python docutils.nodes.caution() Examples

The following are 2 code examples of docutils.nodes.caution(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module docutils.nodes , or try the search function .
Example #1
Source File: parsable_text.py    From INGInious with GNU Affero General Public License v3.0 5 votes vote down vote up
def run(self):
        self.assert_has_content()

        hidden_until = self.arguments[0]
        try:
            hidden_until = parse_date(hidden_until)
        except:
            raise self.error('Unknown date format in the "%s" directive; '
                             '%s' % (self.name, hidden_until))

        force_show = self.state.document.settings.force_show_hidden_until
        translation = _get_inginious_translation()

        after_deadline = hidden_until <= datetime.now()
        if after_deadline or force_show:
            output = []

            # Add a warning for teachers/tutors/...
            if not after_deadline and force_show:
                node = nodes.caution()
                self.add_name(node)
                text = translation.gettext("The feedback below will be hidden to the students until {}.").format(
                    hidden_until.strftime("%d/%m/%Y %H:%M:%S"))
                self.state.nested_parse(StringList(text.split("\n")), 0, node)
                output.append(node)

            text = '\n'.join(self.content)
            node = nodes.compound(text)
            self.add_name(node)
            self.state.nested_parse(self.content, self.content_offset, node)
            output.append(node)

            return output
        else:
            node = nodes.caution()
            self.add_name(node)
            text = translation.gettext(
                "A part of this feedback is hidden until {}. Please come back later and reload the submission to see the full feedback.").format(
                hidden_until.strftime("%d/%m/%Y %H:%M:%S"))
            self.state.nested_parse(StringList(text.split("\n")), 0, node)
            return [node] 
Example #2
Source File: parsable_text.py    From INGInious with GNU Affero General Public License v3.0 4 votes vote down vote up
def visit_admonition(self, node):
            """ Support for bootstrap alert/cards """
            node['classes'].insert(0, 'admonition')
            converter = {
                'danger': 'danger',
                'attention': 'warning',
                'caution': 'warning',
                'error': 'danger',
                'hint': 'info',
                'important': 'warning',
                'note': 'default',
                'tip': 'info',
                'warning': 'warning',
                'success': 'success',
                'info': 'info',
                'primary': 'primary',
                'secondary': 'secondary',
                'light': 'light',
                'dark': 'dark'
            }
            cls = [x if not x.startswith('admonition-') else x[11:] for x in node['classes']]
            cls = [converter.get(x) for x in cls if converter.get(x) is not None]
            if len(cls) == 0:
                cls = 'info'
            else:
                cls = cls[0]

            if "title" in node and node['title'] != "":
                self.body.append(self.starttag(node, 'div', CLASS='card mb-3 border-' + cls))

                card_color = "bg-" + cls
                if cls not in ['default', 'light', 'secondary']:
                    card_color += ' text-white'

                self.body.append(self.starttag(node, 'div', CLASS='card-header ' + card_color))
                self.body.append(self.encode(node['title']))
                self.body.append('</div>\n')
                self.body.append(self.starttag(node, 'div', CLASS='card-body'))
            else:
                if cls == "default":
                    cls = 'light'
                self.body.append(self.starttag(node, 'div', CLASS='alert alert-' + cls))
            self.set_first_last(node)

            # drop unneeded title
            node.children = node.children[1:]