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 18, 2019
1 parent e3139e3 commit 8515eb2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 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)
31 changes: 31 additions & 0 deletions judge/migrations/0088_compiler_message_ansi2html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 2.1.12 on 2019-09-17 13:30
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).iterator():
sub.error = clean_html(lh.fromstring(sub.error)).text_content() if sub.error else None
sub.save(update_fields=['error'])


class Migration(migrations.Migration):

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

operations = [
migrations.AlterField(
model_name='submission',
name='error',
field=models.TextField(null=True, verbose_name='compile errors'),
),
migrations.RunPython(strip_error_html, migrations.RunPython.noop, atomic=True),
]
2 changes: 1 addition & 1 deletion judge/models/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Submission(models.Model):
status = models.CharField(verbose_name=_('status'), max_length=2, choices=STATUS, default='QU', db_index=True)
result = models.CharField(verbose_name=_('result'), max_length=3, choices=SUBMISSION_RESULT,
default=None, null=True, blank=True, db_index=True)
error = models.TextField(verbose_name=_('compile errors'), null=True, blank=True)
error = models.TextField(verbose_name=_('compile errors'), null=True)
current_testcase = models.IntegerField(default=0)
batch = models.BooleanField(verbose_name=_('batched cases'), default=False)
case_points = models.FloatField(verbose_name=_('test case points'), default=0)
Expand Down
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 8515eb2

Please sign in to comment.