def _lint_output(linter, count, violations_list, is_html=False, limit=0): """ Given a count & list of pylint violations, pretty-print the output. If `is_html`, will print out with HTML markup. """ if is_html: lines = ['<body>\n'] sep = '-------------<br/>\n' title = HTML("<h1>Quality Report: {}</h1>\n").format(linter) violations_bullets = ''.join( [HTML('<li>{violation}</li><br/>\n').format(violation=violation) for violation in violations_list] ) violations_str = HTML('<ul>\n{bullets}</ul>\n').format(bullets=HTML(violations_bullets)) violations_count_str = HTML("<b>Violations</b>: {count}<br/>\n") fail_line = HTML("<b>FAILURE</b>: {} count should be 0<br/>\n").format(linter) else: lines = [] sep = '-------------\n' title = "Quality Report: {}\n".format(linter) violations_str = ''.join(violations_list) violations_count_str = "Violations: {count}\n" fail_line = "FAILURE: {} count should be {}\n".format(linter, limit) violations_count_str = violations_count_str.format(count=count) lines.extend([sep, title, sep, violations_str, sep, violations_count_str]) if count > limit > -1: lines.append(fail_line) lines.append(sep + '\n') if is_html: lines.append('</body>') return ''.join(lines)
def public_view(self, _context): """ Default message for blocks that don't implement public_view public_view is shown when users aren't logged in and/or are not enrolled in a particular course. """ alert_html = HTML( '<div class="page-banner"><div class="alert alert-warning">' '<span class="icon icon-alert fa fa fa-warning" aria-hidden="true"></span>' '<div class="message-content">{}</div></div></div>') # Determine if the user is seeing public_view because they're not logged in or because they're not enrolled. # (Note: 'self.runtime.user' is not part of the XBlock API and some runtimes don't provide it, but this mixin is # part of the runtime so it's OK to access it that way.) if self.runtime.user is None or self.runtime.user.is_anonymous: display_text = _( 'This content is only accessible to registered learners. Sign in or register to view it.' ) else: # This is a registered user but they're still seeing public_view # so they must be excluded because of enrollment status. display_text = _( 'This content is only accessible to enrolled learners. ') return Fragment(alert_html.format(display_text))