annotate render_datatable.py @ 0:d4690e65afcd draft

Uploaded
author bcclaywell
date Thu, 26 Feb 2015 18:16:36 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
1 #!/usr/bin/env python
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
2
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
3 import csv
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
4 import itertools
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
5 import string
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
6 import sys
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
7
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
8 input = sys.stdin
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
9 start_lines = input.readlines(10)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
10 all_input = itertools.chain(iter(start_lines), input)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
11
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
12 def detect_delimiter(iterable, char_set):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
13 matches = (c for c in char_set if c in iterable)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
14 return next(matches, None)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
15
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
16 def detect_csv_dialect(sample):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
17 try:
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
18 return csv.Sniffer().sniff(sample)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
19 except:
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
20 return None
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
21
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
22 delimiter = detect_delimiter(start_lines[0], list('\t, '))
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
23 reader = None
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
24
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
25 if delimiter in list('\t,'):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
26 # try to detect csv dialect, which should neatly handle quoted separators and stuff
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
27 dialect = detect_csv_dialect(''.join(start_lines))
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
28 if dialect:
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
29 reader = csv.reader(all_input, dialect)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
30
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
31 if not reader:
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
32 if delimiter in list(string.whitespace):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
33 # use str.split() with no arguments to split on arbitrary whitespace strings
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
34 reader = (line.strip().split() for line in all_input)
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
35 else:
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
36 reader = all_input
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
37
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
38 print """\
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
39 <!DOCTYPE html>
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
40 <html lang="en">
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
41 <head>
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
42 <meta http-equiv="content-type" content="text/html; charset=UTF-8"></meta>
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
43 <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
44 <style>
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
45 div.dataTables_length label {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
46 float: left;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
47 text-align: left;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
48 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
49
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
50 div.dataTables_length select {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
51 width: 75px;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
52 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
53
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
54 div.dataTables_filter label {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
55 float: right;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
56 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
57
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
58 div.dataTables_info {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
59 padding-top: 8px;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
60 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
61
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
62 div.dataTables_paginate {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
63 float: right;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
64 margin: 0;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
65 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
66
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
67 table.table {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
68 clear: both;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
69 margin-bottom: 6px !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
70 max-width: none !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
71 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
72
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
73 table.table thead .sorting,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
74 table.table thead .sorting_asc,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
75 table.table thead .sorting_desc,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
76 table.table thead .sorting_asc_disabled,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
77 table.table thead .sorting_desc_disabled {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
78 cursor: pointer;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
79 *cursor: hand;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
80 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
81
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
82
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
83 table.table thead .sorting { background: url('images/sort_both.png') no-repeat center right; }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
84
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
85 //table.table thead .sorting_asc { background: url('images/sort_asc.png') no-repeat center right; }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
86 //table.table thead .sorting_desc { background: url('images/sort_desc.png') no-repeat center right; }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
87 table.table thead .sorting_asc { background: url('http://cdn3.iconfinder.com/data/icons/fatcow/16x16_0140/bullet_arrow_up.png') no-repeat center right; }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
88 table.table thead .sorting_desc { background: url('http://cdn3.iconfinder.com/data/icons/fatcow/16x16_0140/bullet_arrow_down.png') no-repeat center right; }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
89
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
90 table.table thead .sorting_asc_disabled { background: url('images/sort_asc_disabled.png') no-repeat center right; }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
91 table.table thead .sorting_desc_disabled { background: url('images/sort_desc_disabled.png') no-repeat center right; }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
92
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
93 table.dataTable th:active {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
94 outline: none;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
95 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
96
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
97 /* Scrolling */
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
98 div.dataTables_scrollHead table {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
99 margin-bottom: 0 !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
100 border-bottom-left-radius: 0;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
101 border-bottom-right-radius: 0;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
102 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
103
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
104 div.dataTables_scrollHead table thead tr:last-child th:first-child,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
105 div.dataTables_scrollHead table thead tr:last-child td:first-child {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
106 border-bottom-left-radius: 0 !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
107 border-bottom-right-radius: 0 !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
108 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
109
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
110 div.dataTables_scrollBody table {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
111 border-top: none;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
112 margin-bottom: 0 !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
113 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
114
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
115 div.dataTables_scrollBody tbody tr:first-child th,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
116 div.dataTables_scrollBody tbody tr:first-child td {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
117 border-top: none;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
118 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
119
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
120 div.dataTables_scrollFoot table {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
121 border-top: none;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
122 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
123
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
124
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
125
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
126
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
127 /*
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
128 * TableTools styles
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
129 */
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
130 .table tbody tr.active td,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
131 .table tbody tr.active th {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
132 background-color: #08C;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
133 color: white;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
134 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
135
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
136 .table tbody tr.active:hover td,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
137 .table tbody tr.active:hover th {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
138 background-color: #0075b0 !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
139 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
140
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
141 .table-striped tbody tr.active:nth-child(odd) td,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
142 .table-striped tbody tr.active:nth-child(odd) th {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
143 background-color: #017ebc;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
144 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
145
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
146 table.DTTT_selectable tbody tr {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
147 cursor: pointer;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
148 *cursor: hand;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
149 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
150
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
151 div.DTTT .btn {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
152 color: #333 !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
153 font-size: 12px;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
154 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
155
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
156 div.DTTT .btn:hover {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
157 text-decoration: none !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
158 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
159
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
160
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
161 ul.DTTT_dropdown.dropdown-menu a {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
162 color: #333 !important; /* needed only when demo_page.css is included */
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
163 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
164
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
165 ul.DTTT_dropdown.dropdown-menu li:hover a {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
166 background-color: #0088cc;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
167 color: white !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
168 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
169
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
170 /* TableTools information display */
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
171 div.DTTT_print_info.modal {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
172 height: 150px;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
173 margin-top: -75px;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
174 text-align: center;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
175 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
176
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
177 div.DTTT_print_info h6 {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
178 font-weight: normal;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
179 font-size: 28px;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
180 line-height: 28px;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
181 margin: 1em;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
182 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
183
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
184 div.DTTT_print_info p {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
185 font-size: 14px;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
186 line-height: 20px;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
187 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
188
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
189
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
190
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
191 /*
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
192 * FixedColumns styles
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
193 */
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
194 div.DTFC_LeftHeadWrapper table,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
195 div.DTFC_LeftFootWrapper table,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
196 table.DTFC_Cloned tr.even {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
197 background-color: white;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
198 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
199
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
200 div.DTFC_LeftHeadWrapper table {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
201 margin-bottom: 0 !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
202 border-top-right-radius: 0 !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
203 border-bottom-left-radius: 0 !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
204 border-bottom-right-radius: 0 !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
205 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
206
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
207 div.DTFC_LeftHeadWrapper table thead tr:last-child th:first-child,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
208 div.DTFC_LeftHeadWrapper table thead tr:last-child td:first-child {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
209 border-bottom-left-radius: 0 !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
210 border-bottom-right-radius: 0 !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
211 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
212
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
213 div.DTFC_LeftBodyWrapper table {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
214 border-top: none;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
215 margin-bottom: 0 !important;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
216 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
217
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
218 div.DTFC_LeftBodyWrapper tbody tr:first-child th,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
219 div.DTFC_LeftBodyWrapper tbody tr:first-child td {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
220 border-top: none;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
221 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
222
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
223 div.DTFC_LeftFootWrapper table {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
224 border-top: none;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
225 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
226 </style>
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
227 <script type="text/javascript" language="javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.0.min.js"></script>
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
228 <script type="text/javascript" language="javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
229 <script type="text/javascript" charset="utf-8">
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
230 /* Set the defaults for DataTables initialisation */
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
231 $.extend( true, $.fn.dataTable.defaults, {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
232 "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
233 "sPaginationType": "bootstrap",
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
234 "oLanguage": {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
235 "sLengthMenu": "_MENU_ records per page"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
236 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
237 } );
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
238
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
239
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
240 /* Default class modification */
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
241 $.extend( $.fn.dataTableExt.oStdClasses, {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
242 "sWrapper": "dataTables_wrapper form-inline"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
243 } );
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
244
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
245
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
246 /* API method to get paging information */
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
247 $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
248 {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
249 return {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
250 "iStart": oSettings._iDisplayStart,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
251 "iEnd": oSettings.fnDisplayEnd(),
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
252 "iLength": oSettings._iDisplayLength,
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
253 "iTotal": oSettings.fnRecordsTotal(),
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
254 "iFilteredTotal": oSettings.fnRecordsDisplay(),
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
255 "iPage": oSettings._iDisplayLength === -1 ?
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
256 0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
257 "iTotalPages": oSettings._iDisplayLength === -1 ?
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
258 0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
259 };
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
260 };
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
261
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
262
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
263 /* Bootstrap style pagination control */
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
264 $.extend( $.fn.dataTableExt.oPagination, {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
265 "bootstrap": {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
266 "fnInit": function( oSettings, nPaging, fnDraw ) {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
267 var oLang = oSettings.oLanguage.oPaginate;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
268 var fnClickHandler = function ( e ) {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
269 e.preventDefault();
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
270 if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
271 fnDraw( oSettings );
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
272 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
273 };
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
274
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
275 $(nPaging).addClass('pagination').append(
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
276 '<ul>'+
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
277 '<li class="prev disabled"><a href="#">&larr; '+oLang.sPrevious+'</a></li>'+
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
278 '<li class="next disabled"><a href="#">'+oLang.sNext+' &rarr; </a></li>'+
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
279 '</ul>'
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
280 );
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
281 var els = $('a', nPaging);
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
282 $(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
283 $(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
284 },
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
285
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
286 "fnUpdate": function ( oSettings, fnDraw ) {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
287 var iListLength = 5;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
288 var oPaging = oSettings.oInstance.fnPagingInfo();
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
289 var an = oSettings.aanFeatures.p;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
290 var i, ien, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2);
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
291
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
292 if ( oPaging.iTotalPages < iListLength) {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
293 iStart = 1;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
294 iEnd = oPaging.iTotalPages;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
295 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
296 else if ( oPaging.iPage <= iHalf ) {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
297 iStart = 1;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
298 iEnd = iListLength;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
299 } else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
300 iStart = oPaging.iTotalPages - iListLength + 1;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
301 iEnd = oPaging.iTotalPages;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
302 } else {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
303 iStart = oPaging.iPage - iHalf + 1;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
304 iEnd = iStart + iListLength - 1;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
305 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
306
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
307 for ( i=0, ien=an.length ; i<ien ; i++ ) {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
308 // Remove the middle elements
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
309 $('li:gt(0)', an[i]).filter(':not(:last)').remove();
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
310
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
311 // Add the new list items and their event handlers
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
312 for ( j=iStart ; j<=iEnd ; j++ ) {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
313 sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
314 $('<li '+sClass+'><a href="#">'+j+'</a></li>')
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
315 .insertBefore( $('li:last', an[i])[0] )
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
316 .bind('click', function (e) {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
317 e.preventDefault();
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
318 oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
319 fnDraw( oSettings );
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
320 } );
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
321 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
322
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
323 // Add / remove disabled classes from the static elements
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
324 if ( oPaging.iPage === 0 ) {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
325 $('li:first', an[i]).addClass('disabled');
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
326 } else {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
327 $('li:first', an[i]).removeClass('disabled');
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
328 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
329
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
330 if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
331 $('li:last', an[i]).addClass('disabled');
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
332 } else {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
333 $('li:last', an[i]).removeClass('disabled');
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
334 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
335 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
336 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
337 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
338 } );
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
339
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
340
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
341 /*
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
342 * TableTools Bootstrap compatibility
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
343 * Required TableTools 2.1+
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
344 */
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
345 if ( $.fn.DataTable.TableTools ) {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
346 // Set the classes that TableTools uses to something suitable for Bootstrap
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
347 $.extend( true, $.fn.DataTable.TableTools.classes, {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
348 "container": "DTTT btn-group",
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
349 "buttons": {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
350 "normal": "btn",
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
351 "disabled": "disabled"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
352 },
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
353 "collection": {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
354 "container": "DTTT_dropdown dropdown-menu",
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
355 "buttons": {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
356 "normal": "",
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
357 "disabled": "disabled"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
358 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
359 },
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
360 "print": {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
361 "info": "DTTT_print_info modal"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
362 },
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
363 "select": {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
364 "row": "active"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
365 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
366 } );
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
367
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
368 // Have the collection use a bootstrap compatible dropdown
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
369 $.extend( true, $.fn.DataTable.TableTools.DEFAULTS.oTags, {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
370 "collection": {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
371 "container": "ul",
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
372 "button": "li",
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
373 "liner": "a"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
374 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
375 } );
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
376 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
377
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
378
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
379 /* Table initialisation */
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
380 $(document).ready(function() {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
381 $('#from_csv').dataTable( {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
382 "sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
383 "sPaginationType": "bootstrap",
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
384 "oLanguage": {
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
385 "sLengthMenu": "_MENU_ records per page"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
386 }
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
387 } );
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
388 } );
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
389 </script>
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
390 </head>
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
391 <body>
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
392 <div class="container" style="margin-top: 10px">
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
393 <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="from_csv">
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
394 <thead>\
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
395 """
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
396
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
397 for i, row in enumerate(reader):
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
398 if i == 0:
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
399 print "<tr><th>" + "</th><th>".join(row) + "</th></tr>"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
400 else:
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
401 print "<tr><td>" + "</td><td>".join(row) + "</td></tr>"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
402
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
403 if i == 0:
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
404 print "</thead><tbody>"
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
405
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
406 print """\
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
407 </tbody>
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
408 </table>
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
409 </div>
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
410 </body>
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
411 </html>\
d4690e65afcd Uploaded
bcclaywell
parents:
diff changeset
412 """