From b5800e0091cd5ad0a8e2f63a262b4ee65320f7f7 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Sat, 14 Apr 2012 20:35:58 +0200 Subject: [PATCH] Better snippet list. --- .../templates/dpaste/snippet_details.html | 2 +- .../dpaste/templates/dpaste/snippet_list.html | 21 ++++++++++++++----- .../apps/dpaste/templatetags/dpaste_tags.py | 10 ++++++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/pastebin/apps/dpaste/templates/dpaste/snippet_details.html b/pastebin/apps/dpaste/templates/dpaste/snippet_details.html index 1916dfc..1f2ceb0 100644 --- a/pastebin/apps/dpaste/templates/dpaste/snippet_details.html +++ b/pastebin/apps/dpaste/templates/dpaste/snippet_details.html @@ -1,6 +1,7 @@ {% extends "dpaste/base.html" %} {% load mptt_tags %} {% load i18n %} +{% load dpaste_tags %} {% block extrahead %} {% if request.session.userprefs %} @@ -24,7 +25,6 @@ {{ snippet.published|date:_("DATETIME_FORMAT") }} ({% trans "UTC" %}) {% endblock %} -{% load dpaste_tags %} {% block content %} diff --git a/pastebin/apps/dpaste/templates/dpaste/snippet_list.html b/pastebin/apps/dpaste/templates/dpaste/snippet_list.html index 658b522..4b01def 100644 --- a/pastebin/apps/dpaste/templates/dpaste/snippet_list.html +++ b/pastebin/apps/dpaste/templates/dpaste/snippet_list.html @@ -1,7 +1,8 @@ {% extends "dpaste/base.html" %} {% load i18n %} +{% load dpaste_tags %} -{% block title %}{% trans "Snippet" %} #{{ snippet.pk }}{% endblock %} +{% block title %}{% trans "Snippet List" %}{% endblock %} {% block headline %}

{% blocktrans %}Your latest {{ snippets_max }} snippets{% endblocktrans %}

{% endblock %} @@ -10,11 +11,21 @@ {% if snippet_list %} {% for snippet in snippet_list %}

- {% trans "Snippet" %} #{{ snippet.pk }} - ~ {{ snippet.published|date:_("DATETIME_FORMAT") }} + + {{ snippet.published|timesince }} ago +

-

{{ snippet.content|truncatewords:40 }}

- {% endfor %} + +
+ + + + +
{% for l in lines %}{{ forloop.counter }}{% endfor %}
{% for line in snippet|highlight:5 %}
{% if line %}{{ line|safe }}{% else %} {% endif %}
{% endfor %} +... see full snippet.
+
+
+ {% endfor %} {% else %}

{% trans "No snippets available." %}

{% endif %} diff --git a/pastebin/apps/dpaste/templatetags/dpaste_tags.py b/pastebin/apps/dpaste/templatetags/dpaste_tags.py index 1b5279f..d545929 100644 --- a/pastebin/apps/dpaste/templatetags/dpaste_tags.py +++ b/pastebin/apps/dpaste/templatetags/dpaste_tags.py @@ -10,8 +10,12 @@ def in_list(value,arg): return value in arg @register.filter -def highlight(snippet): +def highlight(snippet, maxlines=None): h = pygmentize(snippet.content, snippet.lexer) if not h: - return snippet.content.splitlines() - return h.splitlines() \ No newline at end of file + s = snippet.content.splitlines() + s = h.splitlines() + + if maxlines: + return s[:maxlines] + return s \ No newline at end of file