<commit_before>import os
import sys

from django.conf import settings
from django.core.management.base import BaseCommand
from django.template import Context
from django.template.loader import get_template

from judge.models import Problem
from judge.pdf_problems import WebKitPdfMaker


class Command(BaseCommand):
    help = 'renders a PDF file of a problem'

    def add_arguments(self, parser):
        parser.add_argument('code', help='code of problem to render')
        parser.add_argument('directory', nargs='?', help='directory to store temporaries')

    def handle(self, *args, **options):
        try:
            problem = Problem.objects.get(code=options['code'])
        except Problem.DoesNotExist:
            print 'Bad problem code'
            return

        directory = options['directory']
        with WebKitPdfMaker(directory, clean_up=directory is None) as maker:
            maker.html = get_template('problem/raw.jade').render(Context({
                'problem': problem
            })).replace('"//', '"http://').replace("'//", "'http://")<commit_msg>Make render_pdf command work again; #299 #423<commit_after>import os
import sys

from django.conf import settings
from django.core.management.base import BaseCommand
from django.template import Context
from django.template.loader import get_template
from django.utils import translation

from judge.models import Problem
from judge.pdf_problems import WebKitPdfMaker


class Command(BaseCommand):
    help = 'renders a PDF file of a problem'

    def add_arguments(self, parser):
        parser.add_argument('code', help='code of problem to render')
        parser.add_argument('directory', nargs='?', help='directory to store temporaries')
        parser.add_argument('-l', '--language', default=settings.LANGUAGE_CODE,
                            help='language to render PDF in')

    def handle(self, *args, **options):
        try:
            problem = Problem.objects.get(code=options['code'])
        except Problem.DoesNotExist:
            print 'Bad problem code'
            return

        directory = options['directory']
        with WebKitPdfMaker(directory, clean_up=directory is None) as maker, \
                translation.override(options['language']):
            maker.html = get_template('problem/raw.jade').render(Context({
                'problem': problem
            })).replace('"//', '"http://').replace("'//", "'http://")
{'fraction_non_alphanumeric': 0.1162695152013147, 'fraction_numerical': 0.0024650780608052587, 'mean_word_length': 3.092436974789916, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1444308', 'n_tokens_mistral': 652, 'n_tokens_neox': 630, 'n_words': 184}