def get_context_data(self, **kwargs): context = super(SubmissionSource, self).get_context_data(**kwargs) submission = self.object context['raw_source'] = submission.source.rstrip('\n') context['highlighted_source'] = highlight_code( submission.source, submission.language.pygments) return context
def problem_init_view(request, problem): problem = get_object_or_404(Problem, code=problem) if not request.user.is_superuser and not problem.is_editable_by( request.user): raise Http404() try: with problem_data_storage.open(os.path.join(problem.code, 'init.yml')) as f: data = f.read().rstrip('\n') except IOError: raise Http404() return render( request, 'problem/yaml.jade', { 'raw_source': data, 'highlighted_source': highlight_code(data, 'yaml'), 'title': _('Generated init.yml for %s') % problem.name, 'content_title': mark_safe( escape(_('Generated init.yml for %s')) % (format_html(u'<a href="{1}">{0}</a>', problem.name, reverse('problem_detail', args=[problem.code])))) })
def get_context_data(self, **kwargs): context = super(SubmissionStatus, self).get_context_data(**kwargs) submission = self.object context['last_msg'] = event.last() context['batches'] = group_test_cases(submission.test_cases.all()) context['time_limit'] = submission.problem.time_limit context['raw_source'] = submission.source.rstrip('\n') context['highlighted_source'] = highlight_code(submission.source, submission.language.pygments) try: lang_limit = submission.problem.language_limits.get(language=submission.language) except ObjectDoesNotExist: pass else: context['time_limit'] = lang_limit.time_limit return context
def problem_init_view(request, problem): problem = get_object_or_404(Problem, code=problem) if not request.user.is_superuser and not problem.is_editable_by(request.user): raise Http404() try: with problem_data_storage.open(os.path.join(problem.code, 'init.yml'), 'rb') as f: data = utf8text(f.read()).rstrip('\n') except IOError: raise Http404() return render(request, 'problem/yaml.html', { 'raw_source': data, 'highlighted_source': highlight_code(data, 'yaml'), 'title': _('Generated init.yml for %s') % problem.name, 'content_title': mark_safe(escape(_('Generated init.yml for %s')) % ( format_html('<a href="{1}">{0}</a>', problem.name, reverse('problem_detail', args=[problem.code])))) })
def block_code(self, code, lang=None): if not lang: return '\n<pre><code>%s</code></pre>\n' % mistune.escape(code).rstrip() return highlight_code(code, lang)
def highlight(code, language): return highlight_code(code, language)
def get_context_data(self, **kwargs): context = super(SubmissionSource, self).get_context_data(**kwargs) submission = self.object context['raw_source'] = submission.source.rstrip('\n') context['highlighted_source'] = highlight_code(submission.source, submission.language.pygments) return context