aboutsummaryrefslogtreecommitdiffstats
path: root/beweb
diff options
context:
space:
mode:
authorAaron Bentley <abentley@panoramicfeedback.com>2006-04-06 14:05:47 -0400
committerAaron Bentley <abentley@panoramicfeedback.com>2006-04-06 14:05:47 -0400
commit64ea14acca6f6420ea17c0c2126a71de2c3ef91d (patch)
treea1fdc94063e7d3b5f64c3428a9313dcc33a55f43 /beweb
parente762576b97dc1c7ccbb7b0d07b94d9d42ec36b9d (diff)
downloadbugseverywhere-64ea14acca6f6420ea17c0c2126a71de2c3ef91d.tar.gz
Add ReST support to web front end
Diffstat (limited to 'beweb')
-rw-r--r--beweb/beweb/controllers.py1
-rw-r--r--beweb/beweb/formatting.py73
-rw-r--r--beweb/beweb/templates/edit_bug.kid55
3 files changed, 76 insertions, 53 deletions
diff --git a/beweb/beweb/controllers.py b/beweb/beweb/controllers.py
index 74c6a7d..fc505ed 100644
--- a/beweb/beweb/controllers.py
+++ b/beweb/beweb/controllers.py
@@ -23,6 +23,7 @@ class Comment(PrestHandler):
bug_tree = project_tree(comment_data['project'])
bug = bug_tree.get_bug(comment_data['bug'])
comment = new_comment(bug, "")
+ comment.content_type = "text/restructured"
comment.save()
raise cherrypy.HTTPRedirect(comment_url(comment=comment.uuid,
**comment_data))
diff --git a/beweb/beweb/formatting.py b/beweb/beweb/formatting.py
new file mode 100644
index 0000000..44ed849
--- /dev/null
+++ b/beweb/beweb/formatting.py
@@ -0,0 +1,73 @@
+from StringIO import StringIO
+
+from elementtree.ElementTree import XML
+from libbe.restconvert import rest_xml
+
+def to_unix(text):
+ skip_newline = False
+ for ch in text:
+ if ch not in ('\r', '\n'):
+ yield ch
+ else:
+ if ch == '\n':
+ if skip_newline:
+ continue
+ else:
+ skip_newline = True
+ yield '\n'
+
+
+def soft_text(text):
+ first_space = False
+ translations = {'\n': '<br />\n', '&': '&amp;', '\x3c': '&lt;',
+ '\x3e': '&gt;'}
+ for ch in to_unix(text):
+ if ch == ' ' and first_space is True:
+ yield '&#160;'
+ first_space = ch in (' ')
+ try:
+ yield translations[ch]
+ except KeyError:
+ yield ch
+
+
+def soft_pre(text):
+ return XML('<div style="font-family: monospace">'+
+ ''.join(soft_text(text))+'</div>')
+
+
+def get_rest_body(rest):
+ xml, warnings = rest_xml(StringIO(rest))
+ return xml.find('{http://www.w3.org/1999/xhtml}body'), warnings
+
+
+def comment_body_xhtml(comment):
+ if comment.content_type == "text/restructured":
+ return get_rest_body(comment.body)[0]
+ else:
+ return soft_pre(comment.body)
+
+
+def select_among(name, options, default, display_names=None):
+ output = ['<select name="%s">' % name]
+ for option in options:
+ if option == default:
+ selected = ' selected="selected"'
+ else:
+ selected = ""
+ if display_names is None:
+ display_name = None
+ else:
+ display_name = display_names.get(option)
+
+ if option is None:
+ option = ""
+ if display_name is None:
+ display_name = option
+ value = ""
+ else:
+ value = ' value="%s"' % option
+ output.append("<option%s%s>%s</option>" % (selected, value,
+ display_name))
+ output.append("</select>")
+ return XML("".join(output))
diff --git a/beweb/beweb/templates/edit_bug.kid b/beweb/beweb/templates/edit_bug.kid
index 960866d..c31d660 100644
--- a/beweb/beweb/templates/edit_bug.kid
+++ b/beweb/beweb/templates/edit_bug.kid
@@ -4,58 +4,7 @@ from libbe.bugdir import severity_levels, active_status, inactive_status, thread
from libbe.utility import time_to_str
from beweb.controllers import bug_list_url, comment_url
from beweb.config import people
-def select_among(name, options, default, display_names=None):
- output = ['<select name="%s">' % name]
- for option in options:
- if option == default:
- selected = ' selected="selected"'
- else:
- selected = ""
- if display_names is None:
- display_name = None
- else:
- display_name = display_names.get(option)
-
- if option is None:
- option = ""
- if display_name is None:
- display_name = option
- value = ""
- else:
- value = ' value="%s"' % option
- output.append("<option%s%s>%s</option>" % (selected, value,
- display_name))
- output.append("</select>")
- return XML("".join(output))
-
-def to_unix(text):
- skip_newline = False
- for ch in text:
- if ch not in ('\r', '\n'):
- yield ch
- else:
- if ch == '\n':
- if skip_newline:
- continue
- else:
- skip_newline = True
- yield '\n'
-
-def soft_text(text):
- first_space = False
- translations = {'\n': '<br />\n', '&': '&amp;', '\x3c': '&lt;',
- '\x3e': '&gt;'}
- for ch in to_unix(text):
- if ch == ' ' and first_space is True:
- yield '&#160;'
- first_space = ch in (' ')
- try:
- yield translations[ch]
- except KeyError:
- yield ch
-def soft_pre(text):
- return XML('<div style="font-family: monospace">'+
- ''.join(soft_text(text))+'</div>')
+from beweb.formatting import comment_body_xhtml, select_among
?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"
py:extends="'master.kid'">
@@ -79,7 +28,7 @@ def soft_pre(text):
<tr><td>From</td><td>${comment.From}</td></tr>
<tr><td>Date</td><td>${time_to_str(comment.date)}</td></tr>
</table>
- <div py:content="soft_pre(comment.body)" py:strip="True"></div>
+ <div py:content="comment_body_xhtml(comment)" py:strip="True"></div>
<a href="${comment_url(project_id, bug.uuid, comment.uuid)}">Edit</a>
<a href="${comment_url(project_id, bug.uuid, comment.uuid,
action='Reply')}">Reply</a>