aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsk Solem <askh@opera.com>2009-05-08 16:33:49 +0200
committerAsk Solem <askh@opera.com>2009-05-08 16:33:49 +0200
commit9e56d5194e4138018a1f2a876fbdc16056537800 (patch)
tree3ab4bdd5ea6daf9b128e0e30dd79958deefd8f15
parentceec24d114f2f5da74179c8a4b4abccb8ef86adf (diff)
downloadchishop-9e56d5194e4138018a1f2a876fbdc16056537800.tar.bz2
chishop-9e56d5194e4138018a1f2a876fbdc16056537800.tar.xz
chishop-9e56d5194e4138018a1f2a876fbdc16056537800.zip
Catch restructuredtext exceptions, just show as text instead.
-rw-r--r--djangopypi/templates/djangopypi/pypi_show_links.html4
-rw-r--r--djangopypi/templatetags/safemarkup.py28
2 files changed, 30 insertions, 2 deletions
diff --git a/djangopypi/templates/djangopypi/pypi_show_links.html b/djangopypi/templates/djangopypi/pypi_show_links.html
index c2bbcc6..83142b7 100644
--- a/djangopypi/templates/djangopypi/pypi_show_links.html
+++ b/djangopypi/templates/djangopypi/pypi_show_links.html
@@ -4,8 +4,8 @@
4<p style="font-style: italic;"> 4<p style="font-style: italic;">
5{{ project.summary }} 5{{ project.summary }}
6</p> 6</p>
7{% load markup %} 7{% load safemarkup %}
8{{ project.description|restructuredtext }} 8{{ project.description|saferst }}
9 9
10<br/> 10<br/>
11<table><thead><th>Filename</th><th>Platform</th><th>Type</th><th>Version</th><th>Uploaded On</th><th>Size</th></thead> 11<table><thead><th>Filename</th><th>Platform</th><th>Type</th><th>Version</th><th>Uploaded On</th><th>Size</th></thead>
diff --git a/djangopypi/templatetags/safemarkup.py b/djangopypi/templatetags/safemarkup.py
new file mode 100644
index 0000000..3ecbec8
--- /dev/null
+++ b/djangopypi/templatetags/safemarkup.py
@@ -0,0 +1,28 @@
1from django import template
2from django.conf import settings
3from django.utils.encoding import smart_str, force_unicode
4from django.utils.safestring import mark_safe
5
6register = template.Library()
7
8
9def saferst(value):
10 try:
11 from docutils.core import publish_parts
12 except ImportError:
13 return force_unicode(value)
14
15 docutils_setttings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS",
16 dict())
17
18 try:
19 parts = publish_parts(source=smart_str(value),
20 writer_name="html4css1",
21 settings_overrides=docutils_settings)
22 except:
23 return foce_unicode(value)
24 else:
25 return mark_safe(force_unicode(parts["fragment"]))
26saferst.is_safe = True
27register.filter(saferst)
28