From 14bafb61b743aa84bfbd6c58e61faa00853ff2e2 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 28 Sep 2015 13:26:16 -0400 Subject: [PATCH] Don't render full long snipts on list view. --- snipts/templates/snipts/snipt-list.html | 23 +++++++++++++++++++++-- utils/templatetags/truncate_lines.py | 8 ++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 utils/templatetags/truncate_lines.py diff --git a/snipts/templates/snipts/snipt-list.html b/snipts/templates/snipts/snipt-list.html index b151483..ca06a38 100644 --- a/snipts/templates/snipts/snipt-list.html +++ b/snipts/templates/snipts/snipt-list.html @@ -1,4 +1,4 @@ -{% load humanize snipt_tags %} +{% load humanize snipt_tags truncate_lines %} {% snipt_is_favorited_by_user as 'is_favorited' %} @@ -57,7 +57,26 @@ {% else %} - {{ snipt.stylized|safe }} + {% if snipt.line_count > 300 and not detail %} + + + + + + + +
+
+

+                                          
+
+
+
{{ snipt.code|truncate_lines }}
+
+
+ {% else %} + {{ snipt.stylized|safe }} + {% endif %} {% endif %} {% endif %} {% if snipt.line_count > 8 and not detail and 'snipt-expand' not in snipt.tags_list %} diff --git a/utils/templatetags/truncate_lines.py b/utils/templatetags/truncate_lines.py new file mode 100644 index 0000000..1678993 --- /dev/null +++ b/utils/templatetags/truncate_lines.py @@ -0,0 +1,8 @@ +from django import template + +register = template.Library() + + +@register.filter +def truncate_lines(text): + return '\n'.join(text.split('\n')[:300])