mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 16:12:51 +11:00
Better snippet list.
This commit is contained in:
parent
eb451b8169
commit
b5800e0091
3 changed files with 24 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
||||||
{% extends "dpaste/base.html" %}
|
{% extends "dpaste/base.html" %}
|
||||||
{% load mptt_tags %}
|
{% load mptt_tags %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load dpaste_tags %}
|
||||||
|
|
||||||
{% block extrahead %}
|
{% block extrahead %}
|
||||||
{% if request.session.userprefs %}
|
{% if request.session.userprefs %}
|
||||||
|
@ -24,7 +25,6 @@
|
||||||
<span class="date">{{ snippet.published|date:_("DATETIME_FORMAT") }} ({% trans "UTC" %})</span>
|
<span class="date">{{ snippet.published|date:_("DATETIME_FORMAT") }} ({% trans "UTC" %})</span>
|
||||||
</h1>
|
</h1>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% load dpaste_tags %}
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div id="diff" style="display:none;">diff</div>
|
<div id="diff" style="display:none;">diff</div>
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
{% extends "dpaste/base.html" %}
|
{% extends "dpaste/base.html" %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load dpaste_tags %}
|
||||||
|
|
||||||
{% block title %}{% trans "Snippet" %} #{{ snippet.pk }}{% endblock %}
|
{% block title %}{% trans "Snippet List" %}{% endblock %}
|
||||||
{% block headline %}
|
{% block headline %}
|
||||||
<h1>{% blocktrans %}Your latest {{ snippets_max }} snippets{% endblocktrans %}</h1>
|
<h1>{% blocktrans %}Your latest {{ snippets_max }} snippets{% endblocktrans %}</h1>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -10,10 +11,20 @@
|
||||||
{% if snippet_list %}
|
{% if snippet_list %}
|
||||||
{% for snippet in snippet_list %}
|
{% for snippet in snippet_list %}
|
||||||
<h2>
|
<h2>
|
||||||
<a href="{{ snippet.get_absolute_url }}">{% trans "Snippet" %} #{{ snippet.pk }}</a>
|
<a title="{{ snippet.published|date:_("DATETIME_FORMAT") }}" href="{{ snippet.get_absolute_url }}">
|
||||||
~ {{ snippet.published|date:_("DATETIME_FORMAT") }}
|
{{ snippet.published|timesince }} ago
|
||||||
|
</a>
|
||||||
</h2>
|
</h2>
|
||||||
<p style="color: #555; margin: 8px 0 20px 0;">{{ snippet.content|truncatewords:40 }}</p>
|
|
||||||
|
<div class="snippet">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th><pre class="code">{% for l in lines %}<a href="#l{{ forloop.counter }}" id="l{{ forloop.counter }}">{{ forloop.counter }}</a>{% endfor %}</pre></th>
|
||||||
|
<td><pre class="code">{% for line in snippet|highlight:5 %}<div class="line" id="l{{ forloop.counter }}">{% if line %}{{ line|safe }}{% else %} {% endif %}</div>{% endfor %}
|
||||||
|
<a title="{{ snippet.published|date:_("DATETIME_FORMAT") }}" href="{{ snippet.get_absolute_url }}">... see full snippet.</a></pre><td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>{% trans "No snippets available." %}</p>
|
<p>{% trans "No snippets available." %}</p>
|
||||||
|
|
|
@ -10,8 +10,12 @@ def in_list(value,arg):
|
||||||
return value in arg
|
return value in arg
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def highlight(snippet):
|
def highlight(snippet, maxlines=None):
|
||||||
h = pygmentize(snippet.content, snippet.lexer)
|
h = pygmentize(snippet.content, snippet.lexer)
|
||||||
if not h:
|
if not h:
|
||||||
return snippet.content.splitlines()
|
s = snippet.content.splitlines()
|
||||||
return h.splitlines()
|
s = h.splitlines()
|
||||||
|
|
||||||
|
if maxlines:
|
||||||
|
return s[:maxlines]
|
||||||
|
return s
|
Loading…
Reference in a new issue