Change how we display review text to follow the tecnique used with other large blocks of pasted or imported text (shepherds writeups for instance). Fixes #2104. Commit ready for merge.
- Legacy-Id: 12588
This commit is contained in:
parent
6f6406b097
commit
7c182375af
|
@ -297,7 +297,7 @@ def add_events_message_info(events):
|
|||
e.in_reply_to = e.addedmessageevent.in_reply_to
|
||||
|
||||
|
||||
def get_unicode_document_content(key, filename, split=True, markup=True, codec='utf-8', errors='ignore', width=None):
|
||||
def get_unicode_document_content(key, filename, codec='utf-8', errors='ignore'):
|
||||
try:
|
||||
with open(filename, 'rb') as f:
|
||||
raw_content = f.read().decode(codec,errors)
|
||||
|
@ -305,11 +305,7 @@ def get_unicode_document_content(key, filename, split=True, markup=True, codec='
|
|||
error = "Error; cannot read ("+key+")"
|
||||
return error
|
||||
|
||||
if markup:
|
||||
return markup_txt.markup_unicode(raw_content, split, width)
|
||||
else:
|
||||
return raw_content
|
||||
|
||||
return raw_content
|
||||
|
||||
def get_document_content(key, filename, split=True, markup=True):
|
||||
try:
|
||||
|
|
|
@ -582,8 +582,10 @@ def document_main(request, name, rev=None):
|
|||
if doc.type_id == "review":
|
||||
basename = "{}.txt".format(doc.name, doc.rev)
|
||||
pathname = os.path.join(doc.get_file_path(), basename)
|
||||
content = get_unicode_document_content(basename, pathname, split=False, width=80)
|
||||
|
||||
content = get_unicode_document_content(basename, pathname)
|
||||
# If we want to go back to using markup_txt.markup_unicode, call it explicitly here like this:
|
||||
# content = markup_txt.markup_unicode(content, split=False, width=80)
|
||||
|
||||
review_req = ReviewRequest.objects.filter(review=doc.name).first()
|
||||
|
||||
other_reviews = []
|
||||
|
|
|
@ -113,6 +113,6 @@
|
|||
<h2>{{ doc.type.name }}<br><small>{{ doc.name }}</small></h2>
|
||||
|
||||
{% if doc.rev and content != None %}
|
||||
{{ content|safe|keep_spacing|sanitize_html|safe }}
|
||||
<pre class="pasted">{{ content|urlize|safe|sanitize_html|safe }}</pre>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -78,7 +78,7 @@ def markup(content, split=True, width=None):
|
|||
else:
|
||||
return "<pre>" + content + "</pre>\n"
|
||||
|
||||
def markup_unicode(content, split=True, width=None):
|
||||
def markup_unicode(content, split=True, width=None, container_classes=None):
|
||||
# normalize line endings to LF only
|
||||
content = content.replace("\r\n", "\n")
|
||||
content = content.replace("\r", "\n")
|
||||
|
@ -93,11 +93,12 @@ def markup_unicode(content, split=True, width=None):
|
|||
content = fill(content, width)
|
||||
|
||||
# expand tabs + escape
|
||||
content = escape(content.expandtabs())
|
||||
content_to_show = escape(content.expandtabs())
|
||||
|
||||
if split:
|
||||
n = content.find("\n", 5000)
|
||||
content1 = "<pre>"+content[:n+1]+"</pre>\n"
|
||||
return content1
|
||||
else:
|
||||
return "<pre>" + content + "</pre>\n"
|
||||
content_to_show = content_to_show[:n+1]
|
||||
|
||||
pre = '<pre class="%s" >' % container_classes if container_classes else '<pre>'
|
||||
|
||||
return pre+content_to_show+'</pre>\n'
|
||||
|
|
Loading…
Reference in a new issue