[extensions-web] Don't shuttle raw data over AJAX to JS, count lines on the Python side
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] Don't shuttle raw data over AJAX to JS, count lines on the Python side
- Date: Wed, 26 Oct 2011 20:07:05 +0000 (UTC)
commit d06bb232c7a6b85598e05ba4f2b28e2914912e14
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Oct 26 13:17:21 2011 -0400
Don't shuttle raw data over AJAX to JS, count lines on the Python side
sweettooth/review/views.py | 16 +++++++---------
sweettooth/static/js/review.js | 11 ++---------
2 files changed, 9 insertions(+), 18 deletions(-)
---
diff --git a/sweettooth/review/views.py b/sweettooth/review/views.py
index 3e8487e..2727976 100644
--- a/sweettooth/review/views.py
+++ b/sweettooth/review/views.py
@@ -62,8 +62,6 @@ def ajax_get_files_view(request, obj):
zipfile = obj.get_zipfile('r')
- show_linenum = False
-
# filename => { raw, html, filename }
files = []
for filename in zipfile.namelist():
@@ -71,11 +69,14 @@ def ajax_get_files_view(request, obj):
base, extension = os.path.splitext(filename)
+ file_ = dict(filename=filename)
+
if extension in IMAGE_TYPES:
mime = IMAGE_TYPES[extension]
raw_base64 = base64.standard_b64encode(raw)
- html = '<img src="data:%s;base64,%s">' % (mime, raw_base64,)
+ file_.update(html='<img src="data:%s;base64,%s">' % (mime, raw_base64,),
+ num_lines=0)
else:
try:
@@ -88,13 +89,10 @@ def ajax_get_files_view(request, obj):
else:
lexer = pygments.lexers.get_lexer_by_name('text')
- html = pygments.highlight(raw, lexer, formatter)
- show_linenum = True
+ file_.update(html=pygments.highlight(raw, lexer, formatter),
+ num_lines=len(raw.strip().splitlines()))
- files.append(dict(filename=filename,
- raw=raw,
- html=html,
- show_linenum=show_linenum))
+ files.append(file_)
return files
diff --git a/sweettooth/static/js/review.js b/sweettooth/static/js/review.js
index a2004ec..e586168 100644
--- a/sweettooth/static/js/review.js
+++ b/sweettooth/static/js/review.js
@@ -8,15 +8,8 @@ define(['jquery'], function($) {
$tr = $('<tr>');
$table = $('<table>').append($tr);
- if (data.show_linenum) {
- var rawLines = data.raw.split("\n");
- var count = rawLines.length;
-
- if (rawLines[count-1] == "")
- count --;
- if (rawLines[0] == "")
- count --;
-
+ if (data.num_lines) {
+ var count = data.num_lines;
var lines = [];
lines.push("<td class=\"linenumbers\"><pre>");
for (var i = 1; i < (count + 1); i ++) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]