Skip to content

Commit

Permalink
Move ANSI HTML-ifying to site; DMOJ/judge-server#478
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjaclasher authored and Xyene committed Sep 29, 2019
1 parent 18816e7 commit e5297dd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
6 changes: 6 additions & 0 deletions judge/jinja2/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections import defaultdict
from urllib.parse import urljoin

from ansi2html import Ansi2HTMLConverter
from django.contrib.auth.models import AbstractUser
from django.urls import reverse
from lxml.html import Element
Expand Down Expand Up @@ -178,3 +179,8 @@ def join(first, second, *rest):
if not rest:
return urljoin(first, second)
return urljoin(urljoin(first, second), *rest)


@registry.filter(name='ansi2html')
def ansi2html(s):
return Ansi2HTMLConverter(inline=True).convert(s, full=False)
23 changes: 23 additions & 0 deletions judge/migrations/0091_compiler_message_ansi2html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
import lxml.html as lh
from django.db import migrations
from lxml.html.clean import clean_html


def strip_error_html(apps, schema_editor):
Submission = apps.get_model('judge', 'Submission')
for sub in Submission.objects.filter(error__isnull=False).iterator():
if sub.error:
sub.error = clean_html(lh.fromstring(sub.error)).text_content()
sub.save(update_fields=['error'])


class Migration(migrations.Migration):

dependencies = [
('judge', '0090_fix_contest_visibility'),
]

operations = [
migrations.RunPython(strip_error_html, migrations.RunPython.noop, atomic=True),
]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ jsonfield
pymoss
packaging
celery
ansi2html
4 changes: 2 additions & 2 deletions templates/submission/status-testcases.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ <h4>{{ _('We are waiting for a suitable judge to process your submission...') }}
<h4>{{ _('Your submission is being processed...') }}</h4>
{% elif submission.status == 'CE' %}
<h3>{{ _('Compilation Error') }}</h3>
<pre>{{ submission.error|safe }}</pre>
<pre>{{ submission.error|ansi2html }}</pre>
{% else %}
{% if submission.error %}
<h3>{{ _('Compilation Warnings') }}</h3>
<pre>{{ submission.error|safe }}</pre>
<pre>{{ submission.error|ansi2html }}</pre>
<hr class="half-hr"><br>
{% endif %}
{% if is_pretest %}
Expand Down

0 comments on commit e5297dd

Please sign in to comment.