コード例 #1
0
 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
コード例 #2
0
ファイル: problem_data.py プロジェクト: luobuccc/DMOJ_site
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]))))
        })
コード例 #3
0
 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
コード例 #4
0
ファイル: problem_data.py プロジェクト: DMOJ/site
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]))))
    })
コード例 #5
0
 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)
コード例 #6
0
ファイル: code_highlight.py プロジェクト: sunde41/site
def highlight(code, language):
    return highlight_code(code, language)
コード例 #7
0
ファイル: submission.py プロジェクト: awaykened/site
 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
コード例 #8
0
ファイル: code_highlight.py プロジェクト: DMOJ/site
def highlight(code, language):
    return highlight_code(code, language)