From b9c6451f88caa35ab39b6468a99b147d7d7f4937 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 20 Mar 2011 15:51:02 -0500 Subject: Fix news preview with CSRF and AJAX in Django 1.2.5 Signed-off-by: Dan McGee --- media/archweb.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'media/archweb.js') diff --git a/media/archweb.js b/media/archweb.js index 52e817a4..03358fa9 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -71,16 +71,18 @@ if (typeof $.tablesorter !== 'undefined') { /* news/add.html */ function enablePreview() { - $('#previewbtn').click(function(event) { + $('#news-preview-button').click(function(event) { event.preventDefault(); - $.post('/news/preview/', - { data: $('#id_content').val() }, + $.post('/news/preview/', { + data: $('#id_content').val(), + csrfmiddlewaretoken: $('#newsform input[name=csrfmiddlewaretoken]').val() + }, function(data) { - $('#previewdata').html(data); - $('.news-article').show(); + $('#news-preview-data').html(data); + $('#news-preview').show(); } ); - $('#previewtitle').html($('#id_title').val()); + $('#news-preview-title').html($('#id_title').val()); }); } -- cgit v1.2.3-2-g168b From 8de1bd0639a8b6117bc35dfe0ad1e6a1ac34f715 Mon Sep 17 00:00:00 2001 From: Evangelos Foutras Date: Sat, 30 Apr 2011 15:15:38 +0300 Subject: Add filesizeformat filter to sizes in reports/big We also add a new 'filesize' tablesorter parser that handles all the suffixes found in django's filesizeformat filter. Signed-off-by: Dan McGee --- media/archweb.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'media/archweb.js') diff --git a/media/archweb.js b/media/archweb.js index 03358fa9..78b15670 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -67,6 +67,33 @@ if (typeof $.tablesorter !== 'undefined') { }, type: 'numeric' }); + $.tablesorter.addParser({ + id: 'filesize', + re: /^(\d+(?:\.\d+)?) (bytes?|KB|MB|GB|TB)$/, + is: function(s) { + return this.re.test(s); + }, + format: function(s) { + var matches = this.re.exec(s); + var size = parseFloat(matches[1]); + var suffix = matches[2]; + + switch(suffix) { + case 'byte': + case 'bytes': + return size; + case 'KB': + return size * 1024; + case 'MB': + return size * 1024 * 1024; + case 'GB': + return size * 1024 * 1024 * 1024; + case 'TB': + return size * 1024 * 1024 * 1024 * 1024; + } + }, + type: 'numeric' + }); } /* news/add.html */ -- cgit v1.2.3-2-g168b From 98d2608bf2b120a3dde1128069b4ac89a2601f86 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 2 May 2011 11:05:56 -0500 Subject: Ensure we can handle all values in file size columns Signed-off-by: Dan McGee --- media/archweb.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'media/archweb.js') diff --git a/media/archweb.js b/media/archweb.js index 78b15670..49f2a319 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -69,12 +69,13 @@ if (typeof $.tablesorter !== 'undefined') { }); $.tablesorter.addParser({ id: 'filesize', - re: /^(\d+(?:\.\d+)?) (bytes?|KB|MB|GB|TB)$/, + re: /^(\d+(?:\.\d+)?) (bytes?|KB|MB|GB|TB|PB)$/, is: function(s) { return this.re.test(s); }, format: function(s) { var matches = this.re.exec(s); + if (!matches) return 0; var size = parseFloat(matches[1]); var suffix = matches[2]; @@ -90,6 +91,8 @@ if (typeof $.tablesorter !== 'undefined') { return size * 1024 * 1024 * 1024; case 'TB': return size * 1024 * 1024 * 1024 * 1024; + case 'PB': + return size * 1024 * 1024 * 1024 * 1024 * 1024; } }, type: 'numeric' -- cgit v1.2.3-2-g168b