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 committed Sep 17, 2019
1 parent e3139e3 commit 0a0a0db
Show file tree
Hide file tree
Showing 4 changed files with 34 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)
25 changes: 25 additions & 0 deletions judge/migrations/0088_submission_error_html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import lxml.html as lh
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):
sub.error = clean_html(lh.fromstring(sub.error)).text_content()
sub.save(update_fields=['error'])


class Migration(migrations.Migration):

dependencies = [
('judge', '0087_problem_resource_limits'),
]

operations = [
migrations.RunPython(strip_error_html, migrations.RunPython.noop),
]
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 0a0a0db

Please sign in to comment.