Convert most loose templates; #635

This commit is contained in:
Quantum 2017-12-07 13:16:25 -05:00
parent 92ee69d1e8
commit 3c6741d6a8
32 changed files with 321 additions and 294 deletions

View File

@ -8,7 +8,7 @@ from statici18n.templatetags.statici18n import inlinei18n
from judge.highlight_code import highlight_code
from judge.user_translations import ugettext
from . import registry
from . import language, filesize, gravatar, rating, markdown, reference, social, submission, timedelta
from . import language, filesize, gravatar, rating, markdown, reference, render, social, submission, timedelta
registry.function('str', unicode)
registry.filter('str', unicode)

View File

@ -1,13 +1,21 @@
import hashlib
from django.contrib.auth.models import AbstractUser
from django.utils.http import urlencode
from judge.models import Profile
from . import registry
@registry.function
def gravatar(email, size=80, default=None):
email = getattr(email, 'email', email)
if isinstance(email, Profile):
if default is None:
default = email.mute
email = email.user.email
elif isinstance(email, AbstractUser):
email = email.email
gravatar_url = '//www.gravatar.com/avatar/' + hashlib.md5(email.strip().lower()).hexdigest() + '?'
args = {'d': 'identicon', 's': str(size)}
if default:

27
judge/jinja2/render.py Normal file
View File

@ -0,0 +1,27 @@
from django.template import (Template as DjangoTemplate, TemplateSyntaxError as DjangoTemplateSyntaxError,
VariableDoesNotExist)
from . import registry
MAX_CACHE = 100
django_cache = {}
def compile_template(code):
if code in django_cache:
return django_cache[code]
# If this works for re.compile, it works for us too.
if len(django_cache) > MAX_CACHE:
django_cache.clear()
t = django_cache[code] = DjangoTemplate(code)
return t
@registry.function
def render_django(template, **context):
try:
return compile_template(template).render(context)
except (VariableDoesNotExist, DjangoTemplateSyntaxError):
return 'Error rendering: %r' % template

View File

@ -1,26 +0,0 @@
from django import template
register = template.Library()
template_cache = {}
MAX_CACHE = 100
def compile_template(template_code):
if template_code in template_cache:
return template_cache[template_code]
# If this works for re.compile, it works for us too.
if len(template_cache) > MAX_CACHE:
template_cache.clear()
t = template_cache[template_code] = template.Template(template_code)
return t
@register.simple_tag(name='evaluate', takes_context=True)
def evaluate_tag(context, template_code):
try:
return compile_template(template_code).render(context)
except (template.VariableDoesNotExist, template.TemplateSyntaxError):
return 'Error rendering: %r' % template_code

View File

@ -1,53 +0,0 @@
from itertools import chain
from django.core.cache import cache
from django.core.cache.utils import make_template_fragment_key
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Count, Max
from django.http import HttpResponseRedirect, Http404
from django.utils import timezone
from django.views.generic import CreateView, DetailView, ListView, View, UpdateView
from django.views.generic.detail import SingleObjectMixin
from judge.forms import EditOrganizationForm, NewOrganizationForm, NewMessageForm
from judge.models import Organization, PrivateMessage, Profile
from judge.utils.ranker import ranker
from judge.utils.views import generic_message, TitleMixin
class NewMessage(LoginRequiredMixin, TitleMixin, CreateView):
template_name = 'messages/new.html'
model = PrivateMessage
form_class = NewMessageForm
title = 'New Message'
def get_context_data(self, **kwargs):
context = super(NewMessage, self).get_context_data(**kwargs)
context['target'] = self.target
return context
def form_valid(self, form):
form.instance.registrant = self.request.user.profile
return super(NewMessage, self).form_valid(form)
def get(self, request, *args, **kwargs):
name = request.GET.get('target') if 'target' in request.GET else None
try:
self.target = Profile.objects.get(user__username=self.target)
except ObjectDoesNotExist:
return generic_message(request, 'No such user', 'No user called "%s"' % name)
return super(NewMessage, self).get(request, *args, **kwargs)
class MessageList(LoginRequiredMixin, TitleMixin, ListView):
model = PrivateMessage
template_name = 'messages/list.html'
title = 'Inbox'
def get_context_data(self, **kwargs):
context = super(MessageList, self).get_context_data(**kwargs)
profile = self.request.user.user.profile
context['outgoing'] = PrivateMessage.objects.filter(sender=profile).order_by('-key')
context['incoming'] = PrivateMessage.objects.filter(target=profile).order_by('-read')
return context

View File

@ -1,19 +1,34 @@
{% load staticfiles %}{% load cache %}{% load markdown %}{% load timedelta %}{% load i18n %}{% load tz %}{% load gravatar %}
<div class="sidebox dashboard">
<h3>Dashboard <i class="fa fa-dashboard"></i>
</h3>
<div class="sidebox-content">
<div class="user-gravatar"><img src="{% gravatar_url request.user.email 135 request.user.profile.mute %}" alt="gravatar" width="135px" height="135px"/>
<h3>Dashboard <i class="fa fa-dashboard"></i>
</h3>
<div class="sidebox-content">
<div class="user-gravatar">
<img src="{{ gravatar(request.user, 135) }}"
alt="gravatar" width="135px" height="135px">
</div>
<div class="recently-attempted">
<h4>Recently attempted problems</h4>
<ul>
{% for code, name, problem_points, user_points, s_date in recently_attempted_problems %}
<li>
<a href="{{ url('problem_detail', code) }}">{{ name }}</a>
[<a href="{{ url('user_submissions', code, request.user.username }}">
{{- user_points }}/{{ problem_points|floatformat }}</a>]
<span class="time">
<span data-unix="{{ submission.date|utc|date("c") }}"
class="recent-time moment-time-toggle">
{% trans time=submission.date|date(_("N j, Y, g:i")) %}
on {{ time }}
{% endtrans %}
</span>
</span>
</li>
{% endfor %}
</ul>
</div>
<div class="recommended-problems">
<h4>Recommended problems</h4><i>Coming soon.</i>
</div>
</div>
<div class="recently-attempted">
<h4>Recently attempted problems</h4>
<ul>{% for code,name,problem_points,user_points,s_date in __pyjade_iter(recently_attempted_problems,5) %}
<li><a href="{% url "problem_detail" code %}">{{name|escape}}</a>{{' ['|escape}}<a href="{% url "user_submissions" code request.user.username %}">{{user_points|escape}}/{{problem_points|floatformat|escape}}</a>{{'] '|escape}}<span class="time"><span data-unix="{{ s_date|utc|date:"c" }}" class="recent-time moment-time-toggle">{% blocktrans with time=s_date|date:_("N j, Y, g:i") asvar str_time %}on {{ time }}<span class="relative">{{str_time|escape}}</span><span class="absolute">{{str_time|escape}}</span></span></span>
</li>{% endfor %}
</ul>
</div>
<div class="recommended-problems">
<h4>Recommended problems</h4><i>Coming soon.</i>
</div>
</div>
</div>

View File

@ -130,8 +130,7 @@
{% endfor %}
</div>
{% if page_obj.num_pages > 1 %}
<div style="margin-bottom:10px;margin-top:10px">{% include "list-pages.jade" %}
</div>
<div style="margin-bottom:10px;margin-top:10px">{% include "list-pages.html" %}</div>
{% endif %}
</div>
@ -179,6 +178,7 @@
</div>
</div>
{% endif %}
{% if future_contests %}
<div class="blog-sidebox sidebox">
<h3>{{ _('Upcoming contests') }} <i class="fa fa-trophy"></i></h3>
@ -267,11 +267,7 @@
<a href="{{ ticket.linked_item.get_absolute_url() }}">
{{ ticket.linked_item|item_title }}</a>
</div>
{% with user=ticket.user %}
<div class="user {{ user.display_rank }}">
<a href="{{ url('user_page', user.user.username) }}">{{ user.user.username }}</a>
</div>
{% endwith %}
<div>{{ link_user(ticket.user) }}</div>
</li>
{% endfor %}
</ul>

View File

@ -1 +1 @@
{% load markdown %}{% load rating %}{% load reference %}{{comment.body|with_math:MATH_ENGINE|markdown:"comment"|reference|escape}}
{{ comment.body|markdown('comment', MATH_ENGINE)|reference|str|safe }}

View File

@ -1,13 +1,17 @@
<div class="comment-submit">
<form id="comment-edit" action="{{ request.get_full_path }}" method="post"><span style="display: none" class="comment-id">{{comment.id|escape}}</span><span style="display: none" class="read-back">{% url "comment_content" comment.id %}</span>{% csrf_token %}
<div class="form-errors">{{form.non_field_errors|escape}}
{{form.parent.errors|escape}}
{{form.parent|escape}}
</div>
<div class="comment-post-wrapper">
<div id="comment-form-body">{{form.body|escape}}</div>
</div>
<hr/>
<input style="float: right" type="submit" value="Post!" class="button"/>
</form>
</div>
<form id="comment-edit" action="" method="post">
<span style="display: none" class="comment-id">{{ comment.id }}</span>
<span style="display: none" class="read-back">{{ url('comment_content', comment.id) }}</span>
{% csrf_token %}
<div class="form-errors">
{{ form.non_field_errors }}
{{ form.parent.errors }}
{{ form.parent }}
</div>
<div class="comment-post-wrapper">
<div id="comment-form-body">{{ form.body }}</div>
</div>
<hr/>
<input style="float: right" type="submit" value="Post!" class="button">
</form>
</div>

View File

@ -1,5 +1,13 @@
{% extends "base.jade" %}{% load compress %}{% block media %}{% compress css %}{{form.media.css|escape}}{% endcompress %}{% endblock %}
{% block js_media %}{{form.media.js|escape}}{% endblock %}
{% extends "base.html" %}
{% block media %}
{% compress css %}
{{ form.media.css }}
{% endcompress %}
{% endblock %}
{% block js_media %}
{{ form.media.js }}
{% endblock %}
{% block body %}
<div class="form-area">{% include "comments/edit-ajax.jade" %}
</div>{% endblock %}
<div class="form-area">{% include "comments/edit-ajax.html" %}</div>
{% endblock %}

View File

@ -30,7 +30,7 @@
</div>
{% with author=node.author, user=node.author.user %}
<a href="{{ url('user_page', user.username) }}" class="user">
<img src="{{ gravatar(user, 135, author.mute) }}" class="gravatar">
<img src="{{ gravatar(author, 135) }}" class="gravatar">
</a>
{% endwith %}
</div>
@ -40,7 +40,7 @@
<div class="relative-time"></div>
<span data-unix="{{ node.time|utc|date('c') }}" class="comment-time">
{% trans time=post.publish_on|date(_("N j, Y, g:i")) %}
posted on {{ time }}
commented on {{ time }}
{% endtrans %}
</span>
<span class="comment-spacer"></span>

View File

@ -1,3 +1,5 @@
{% load markdown %}{% load reference %}{% with node=revision.field_dict %}
<div{{__pyjade_attrs(attrs=[('style',(('display: none' if not node['title'] or node['title'].startswith('Re:') else '')))])}} class="comment-title">{{node.title|escape}}</div>
<div class="comment-body">{{node.body|with_math:MATH_ENGINE|markdown:"comment"|reference|escape}}</div>{% endwith %}
{% with node=revision.field_dict %}
<div class="comment-title"{% if not node.title or node.title.startswith('Re:') %}
style="display: none"{% endif %}>{{ node.title }}</div>
<div class="comment-body">{{ node.body|markdown('comment', MATH_ENGINE)|reference|str|safe }}</div>
{% endwith %}

View File

@ -1,14 +1,17 @@
<h2>Votes</h2>
<table class="table">
<thead>
<th>Voter</th>
<th>Score</th>
</thead>
<tbody>{% for vote in __pyjade_iter(votes,1) %}
<tr>{% with user=vote.voter %}
<td{{__pyjade_attrs(attrs=[('class', ((user.display_rank)))])}}><a href="{% url "user_page" user.user.username %}" class="user-name">{{user.user.username|escape}}</a>
</td>{% endwith %}
<td>{{vote.score|escape}}</td>
</tr>{% endfor %}
</tbody>
<thead>
<tr>
<th>Voter</th>
<th>Score</th>
</tr>
</thead>
<tbody>
{% for vote in votes %}
<tr>
<td>{{ link_user(vote.voter) }}</td>
<td>{{ vote.score }}</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@ -1,38 +1,39 @@
<html>
<head>
<title>{{code|escape}} - {{id|escape}}</title>
<style>body {
color: #FFFFFF;
background-color: #000080;
font-family: Lucida Console, serif;
font-size: 14px;
font-smooth: never;
-webkit-font-smoothing: none;
margin-left: 50px;
margin-top: 20px;
}
<head>
<title>{{ code }} - {{ id }}</title>
<style>
body {
color: #FFFFFF;
background-color: #000080;
font-family: Lucida Console, serif;
font-size: 14px;
font-smooth: never;
-webkit-font-smoothing: none;
margin-left: 50px;
margin-top: 20px;
}
a {
color: #FFFFFF;
font-weight: bold
}
a {
color: #FFFFFF;
font-weight: bold
}
pre {
font-family: Lucida Console, serif;
line-height: 1.3;
font-smooth: never;
-webkit-font-smoothing: none;
white-space: pre-wrap;
}
pre {
font-family: Lucida Console, serif;
line-height: 1.3;
font-smooth: never;
-webkit-font-smoothing: none;
white-space: pre-wrap;
}
</style>
</head>
<body>
<h2>SIGSEGV: {{id|escape}}</h2>
<pre>{{description|escape}}
</head>
<body>
<h2>SIGSEGV: {{ id }}</h2>
<pre>{{ description }}
site: fatal signal: Segmentation fault
site died (signal <b>{{code|escape}}</b>, exit -11)<br/><br/>panic: <a href="javascript:history.back()">go back</a>
</pre>
{% if request.user.is_superuser and traceback %}
<pre>{{traceback|escape}}</pre>{% endif %}
</body>
site died (signal <b>{{ code }}</b>, exit -11)<br/><br/>panic: <a href="javascript:history.back()">go back</a></pre>
{% if request.user.is_superuser and traceback %}
<pre>{{ traceback }}</pre>
{% endif %}
</body>
</html>

View File

@ -1,3 +1,5 @@
{% load i18n %}{% if perms.flatpages.change_flatpage %}
<div class="title-line-action">[<a href="{% url "admin:flatpages_flatpage_change" flatpage.id %}">{% trans "Edit" %}</a>]
</div>{% endif %}
{% if perms.flatpages.change_flatpage %}
<div class="title-line-action">
[<a href="{{ url('admin:flatpages_flatpage_change', flatpage.id) }}">{{ _('Edit') }}</a>]
</div>
{% endif %}

View File

@ -1,4 +1,15 @@
{% extends "base.jade" %}{% load evaluate %}{% block title %}{{flatpage.title|escape}} - {{SITE_LONG_NAME|escape}}{% endblock %}
{% extends "base.html" %}
{% block title %}{{ flatpage.title }} - {{ SITE_LONG_NAME }}{% endblock %}
{% block og_title %}
<meta property="og:title" content="{{ flatpage.title }} - {{ SITE_LONG_NAME }}"/>{% endblock %}{% block content_title %}{{flatpage.title|escape}}{% endblock %}
{% block header %}{% include "flatpages/admin_link.jade" %}{% endblock %}{% block body %}{% evaluate flatpage.content %}{% endblock %}
<meta property="og:title" content="{{ flatpage.title }} - {{ SITE_LONG_NAME }}">
{% endblock %}
{% block content_title %}{{ flatpage.title }}{% endblock %}
{% block header %}
{% include "flatpages/admin_link.html" %}
{% endblock %}
{% block body %}
{{ render_django(flatpage.content) }}
{% endblock %}

View File

@ -1,4 +0,0 @@
{% extends "flatpages/markdown-math.jade" %}{% block site_title %}<span style="color: #FFDE05">DM::</span><span style="color: #AAA">Solutions</span>{% endblock %}{% block content_title %}{{flatpage.title|escape}}
{% if perms.judge.change_solution %}
<div class="title-line-action">[<a href="{% url "admin:judge_solution_change" flatpage.id %}">{% trans "Edit" %}</a>]
</div>{% endif %}{% endblock %}

View File

@ -1,6 +1,14 @@
{% extends "base.jade" %}{% load markdown %}{% load staticfiles %}{% load reference %}{% block title %}{{flatpage.title|escape}} - {{SITE_LONG_NAME|escape}}{% endblock %}
{% extends "base.html" %}
{% block title %}{{ flatpage.title }} - {{ SITE_LONG_NAME }}{% endblock %}
{% block og_title %}
<meta property="og:title" content="{{ flatpage.title }} - {{ SITE_LONG_NAME }}"/>{% endblock %}{% block content_title %}{{flatpage.title|escape}}{% endblock %}
{% block header %}{% include "flatpages/admin_link.jade" %}{% endblock %}{% block body %}
<div class="content-description">{{flatpage.content|markdown:"solution"|reference|escape}}
</div>{% endblock %}
<meta property="og:title" content="{{ flatpage.title }} - {{ SITE_LONG_NAME }}">
{% endblock %}
{% block content_title %}{{ flatpage.title }}{% endblock %}
{% block header %}{% include "flatpages/admin_link.html" %}{% endblock %}
{% block body %}
<div class="content-description">{{ flatpage.content|markdown('solution')|reference|str|safe }}</div>
{% endblock %}

View File

@ -1,7 +1,9 @@
{% extends "base.jade" %}{% load markdown %}{% load staticfiles %}{% load reference %}{% block title %}{{flatpage.title|escape}} - {{SITE_LONG_NAME|escape}}{% endblock %}
{% block og_title %}
<meta property="og:title" content="{{ flatpage.title }} - {{ SITE_LONG_NAME }}"/>{% endblock %}{% block content_title %}{{flatpage.title|escape}}{% endblock %}
{% block header %}{% include "flatpages/admin_link.jade" %}{% endblock %}{% block body %}
<div class="content-description">{{flatpage.content|with_math:MATH_ENGINE|markdown:"solution"|reference|escape}}
</div>{% endblock %}
{% block bodyend %}{% if REQUIRE_JAX %}{% include "mathjax-load.jade" %}{% endif %}{% endblock %}
{% extends "flatpages/markdown.html" %}
{% block body %}
<div class="content-description">{{ flatpage.content|markdown('solution', MATH_ENGINE)|reference }}</div>
{% endblock %}
{% block bodyend %}
{% if REQUIRE_JAX %}{% include "mathjax-load.html" %}{% endif %}
{% endblock %}

View File

@ -1,2 +1,5 @@
{% extends "base.jade" %}{% block body %}
<h3>{{message|escape}}</h3>{% endblock %}
{% extends "base.html" %}
{% block body %}
<h3>{{ message }}</h3>
{% endblock %}

View File

@ -1 +1 @@
{% load markdown %}{{preview_data|markdown:"license"|escape}}
{{ preview_data|markdown('license') }}

View File

@ -1,6 +1,13 @@
{% extends "common-content.jade" %}{% load cache %}{% load markdown %}{% load i18n %}{% block description %}{% cache 3600 license_html license.id %}{{license.text|markdown:"license"|escape}}{% endcache %}{% endblock %}
{% block info_float %}{% if perms.judge.change_license %}
<div><a href="{% url "admin:judge_license_change" license.id %}">{% trans "Edit" %}</a>
</div>{% endif %}
<div><b>{% trans "Source:" %}</b> <a{{__pyjade_attrs(attrs=[('href',(license.link))])}}>{{license.link|escape}}</a>
</div>{% endblock %}
{% extends "common-content.html" %}
{% block description %}
{% cache 3600 license_html license.id %}
{{ license.text|markdown('license') }}
{% endcache %}
{% endblock %}
{% block info_float %}
{% if perms.judge.change_license %}
<div><a href="{% url "admin:judge_license_change" license.id %}">{{ _('Edit') }}</a></div>
{% endif %}
<div><b>{{ _('Source:') }}</b> <a href="{{ license.link }}">{{ license.link }}</a></div>
{% endblock %}

View File

@ -1 +0,0 @@
{% for user in __pyjade_iter(users,1) %}<span{{__pyjade_attrs(attrs=[('class', ((user.css_class)))])}}><a href="{% url "user_page" user.user.username %}">{{user.user.username|escape}}</a></span>{% if not forloop.last %}{{', '|escape}}{% endif %}{% endfor %}

View File

@ -1,18 +1,31 @@
<ul class="pagination">{% if page_obj.has_previous %}{% if page_obj.previous_page_number == 1 and first_page_href != None %}
<li><a{{__pyjade_attrs(attrs=[('href',(first_page_href))])}}>«</a>
</li>{% else %}
<li><a href="{{ page_prefix }}{{ page_obj.previous_page_number }}{{ page_suffix }}">«</a>
</li>{% endif %}{% else %}
<li class="disabled-page"><span>«</span>
</li>{% endif %}{% for page in __pyjade_iter(page_obj.page_range,1) %}{% if not page %}
<li class="disabled-page"><span>...</span>
</li>{% else %}{% if page == 1 and first_page_href != None %}
<li{{__pyjade_attrs(attrs=[('class', ((('active-page' if page == page_obj.number else undefined))))])}}><a{{__pyjade_attrs(attrs=[('href',(first_page_href))])}}>{{page|escape}}</a>
</li>{% else %}
<li{{__pyjade_attrs(attrs=[('class', ((('active-page' if page == page_obj.number else undefined))))])}}><a href="{{ page_prefix }}{{ page }}{{ page_suffix }}">{{page|escape}}</a>
</li>{% endif %}{% endif %}{% endfor %}{% if page_obj.has_next %}
<li><a href="{{ page_prefix }}{{ page_obj.next_page_number }}{{ page_suffix }}">»</a>
</li>{% else %}
<li class="disabled-page"><span>»</span>
</li>{% endif %}
</ul>
<ul class="pagination">
{% if page_obj.has_previous %}
{% if page_obj.previous_page_number == 1 and first_page_href != None %}
<li><a href="{{ first_page_href }}">«</a></li>
{% else %}
<li><a href="{{ page_prefix }}{{ page_obj.previous_page_number }}{{ page_suffix }}">«</a></li>
{% endif %}
{% else %}
<li class="disabled-page"><span>«</span></li>
{% endif %}
{% for page in page_obj.page_range %}
{% if not page %}
<li class="disabled-page"><span>...</span></li>
{% else %}
<li{% if page == page_obj.number %} class="active-page"{% endif %}>
<a href="
{%- if page == 1 and first_page_href != None -%}
{{ first_page_href }}
{%- else -%}
{{ page_prefix }}{{ page }}{{ page_suffix }}
{%- endif -%}
">{{ page }}</a>
{% endfor %}
{% if page_obj.has_next %}
<li><a href="{{ page_prefix }}{{ page_obj.next_page_number }}{{ page_suffix }}">»</a></li>
{% else %}
<li class="disabled-page"><span>»</span></li>
{% endif %}
</ul>

View File

@ -1,2 +0,0 @@
{% extends "base.jade" %}{% load staticfiles %}{% for message in __pyjade_iter(incoming,1) %}{% if not message.read %}<b>{{message.title|escape}} &rarr; me <span class="time">({{message.timestamp|escape}})</span></b>{% else %}{{message.title|escape}} &rarr; me<span class="time">({{message.timestamp|escape}})</span>{% endif %}<br/>{% endfor %}<br/>
<div class="dashed"></div><br/>{% for message in __pyjade_iter(outgoing,1) %}{{message.title|escape}} &rarr; {{message.target|escape}}<span class="time">({{message.timestamp|escape}})</span><br/>{% endfor %}

View File

@ -1,11 +0,0 @@
{% extends "base.jade" %}{% load staticfiles %}{% load i18n %}{% block media %}
<link rel="stylesheet" href="{% static "admin/css/widgets.css" %}" type="text/css"/>{{form.media|escape}}
<link rel="stylesheet" href="{% static "admin/css/pagedown.css" %}" type="text/css"/>
<link rel="stylesheet" href="{% static "problem_edit.css" %}" type="text/css"/>{% endblock %}
{% block body %}<b>{% trans "To:" %}</b>{{target|escape}}
<hr/>
<form action="" method="post" class="form-area">{% csrf_token %}
<table border="0" style="text-align:left">{{form.as_table|escape}}</table>
<hr/>
<input type="submit" style="float:right;" value="{% trans "Send!" %}"/>
</form>{% endblock %}

View File

@ -1,3 +1,4 @@
{% load markdown %}{% load staticfiles %}{% load reference %}{{preview_data|with_math:MATH_ENGINE|markdown:"solution"|reference|escape}}
{% if REQUIRE_JAX %}
<div data-config="{% static "mathjax_config.js" %}" class="require-mathjax-support"></div>{% endif %}
{{ preview_data|markdown('solution', MATH_ENGINE)|reference|str|safe }}
{% if REQUIRE_JAX %}
<div data-config="{{ static('mathjax_config.js') }}" class="require-mathjax-support"></div>
{% endif %}

View File

@ -1,9 +0,0 @@
{% extends "base.jade" %}{% load markdown %}{% load staticfiles %}{% load i18n %}{% load reference %}{% block js_media %}{% include "comments/media-js.jade" %}{% endblock %}{% block media %}{% include "comments/media-css.jade" %}{% endblock %}{% block site_title %}<span style="color: #FFDE05">DM::</span><span style="color: #AAA">Solutions</span>{% endblock %}{% block title %}{{solution.title|escape}} - {{SITE_LONG_NAME|escape}}{% endblock %}
{% block content_title %}{{solution.title|escape}}
<div style="float:right">{% if solution.problem %}[<a href="{% url "problem_detail" solution.problem.code %}">{% trans "Problem" %}</a>]{% endif %}
{% if perms.judge.change_solution %}[<a href="{% url "admin:judge_solution_change" solution.id %}">{% trans "Edit" %}</a>]{% endif %}
</div>{% endblock %}
{% block body %}
<div class="content-description">{{solution.content|with_math:MATH_ENGINE|markdown:"solution"|reference|escape}}
</div>
{% include "comments/list.jade" %}{% endblock %}{% block bodyend %}{% if REQUIRE_JAX %}{% include "mathjax-load.jade" %}{% endif %}{% include "comments/math.jade" %}{% endblock %}

View File

@ -1,4 +1,5 @@
{% extends "base.html" %}
{% block js_media %}
{% include "status/media-js.html" %}
{% endblock %}

View File

@ -23,7 +23,7 @@
{% endif %}
<div>
{{ link_user(submission.user) }}
<span data-unix="{{ submission.date|utc|date("c") }}" class="post-time">
<span data-unix="{{ submission.date|utc|date("c") }}">
{% trans time=submission.date|date(_("N j, Y, g:i")) %}
on {{ time }}
{% endtrans %}

View File

@ -1,9 +1,27 @@
{% load compress %}{% load staticfiles %}{% compress css %}{% if TIMEZONE_BG %}
<style>.map-wrap { background: {{TIMEZONE_BG|escape}} }
</style>{% endif %}
<link rel="stylesheet" href="{% static "libs/timezone-map/timezone-map.css" %}"/>
<style>.map-inset { background: url('{{TIMEZONE_MAP|escape}}') 50% 50% }
.map-wrap { display: none }
.featherlight { z-index: 1000 }
.featherlight .featherlight-content { min-width: 80% }
</style>{% endcompress %}
{% compress css %}
{% if TIMEZONE_BG %}
<style>
.map-wrap {
background: url('{{TIMEZONE_BG}}')
}
</style>
{% endif %}
<link rel="stylesheet" href="{{ static('libs/timezone-map/timezone-map.css') }}"/>
<style>
.map-inset {
background: url('{{TIMEZONE_MAP}}') 50% 50%
}
.map-wrap {
display: none
}
.featherlight {
z-index: 1000
}
.featherlight .featherlight-content {
min-width: 80%
}
</style>
{% endcompress %}

View File

@ -1,42 +1,45 @@
{% load compress %}{% load staticfiles %}{% compress js %}
<script src="{% static "libs/featherlight/featherlight.min.js" %}" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="{% static "libs/timezone-map/timezone-picker.js" %}"></script>
<script type="text/javascript">$(function () {
$('#open-map').featherlight({
afterOpen: function () {
timezone_picker($('.featherlight-inner .map-inset'), $('#id_timezone'), '{% static "libs/timezone-map/timezone-picker.json" %}');
}
});
});
if ('geolocation' in navigator) {
$(function () {
$('<span>, <a href="#" id="detect-tz">detect</a></span>').insertAfter('#open-map');
$('#detect-tz').click(function (event) {
var button = $(this).html('detecting...');
navigator.geolocation.getCurrentPosition(function(position) {
$.ajax({
url: 'https://maps.googleapis.com/maps/api/timezone/json',
data: {
location: position.coords.latitude + ',' + position.coords.longitude,
timestamp: Math.floor(Date.now() / 1000)
}
}).done(function (data) {
if (data['timeZoneId'])
$('#id_timezone').val(data.timeZoneId).change();
else
alert('Invalid response from Google: ' + data);
}).fail(function (jqXHR, status) {
alert(status);
}).always(function () {
button.html('detect');
});
}, function () {
button.html('detect');
alert('Unable to detect');
{% compress js %}
<script src="{{ static('libs/featherlight/featherlight.min.js') }}" type="text/javascript"></script>
<script type="text/javascript" src="{{ static('libs/timezone-map/timezone-picker.js') }}"></script>
<script type="text/javascript">
$(function () {
$('#open-map').featherlight({
afterOpen: function () {
timezone_picker($('.featherlight-inner .map-inset'), $('#id_timezone'),
'{{ static('libs/timezone-map/timezone-picker.json') }}');
}
});
event.preventDefault();
});
});
}
</script>{% endcompress %}
if ('geolocation' in navigator) {
$(function () {
$('<span>, <a href="#" id="detect-tz">detect</a></span>').insertAfter('#open-map');
$('#detect-tz').click(function (event) {
var button = $(this).html('detecting...');
navigator.geolocation.getCurrentPosition(function (position) {
$.ajax({
url: 'https://maps.googleapis.com/maps/api/timezone/json',
data: {
location: position.coords.latitude + ',' + position.coords.longitude,
timestamp: Math.floor(Date.now() / 1000)
}
}).done(function (data) {
if (data['timeZoneId'])
$('#id_timezone').val(data.timeZoneId).change();
else
alert('Invalid response from Google: ' + data);
}).fail(function (jqXHR, status) {
alert(status);
}).always(function () {
button.html('detect');
});
}, function () {
button.html('detect');
alert('Unable to detect');
});
event.preventDefault();
});
});
}
</script>
{% endcompress %}