def test_advanced_search_1(self): """ Basics of the advanced search toolkit """ from grad.forms import COLUMN_CHOICES, COLUMN_WIDTHS_DATA from grad.templatetags.getattribute import getattribute cols = set(k for k, v in COLUMN_CHOICES) widths = set(k for k, v in COLUMN_WIDTHS_DATA) self.assertEquals(cols, widths) gs = self.__make_test_grad() for key in cols: # make sure each column returns *something* without error getattribute(gs, key)
def test_advanced_search_1(self): """ Basics of the advanced search toolkit """ from grad.forms import COLUMN_CHOICES, COLUMN_WIDTHS_DATA from grad.templatetags.getattribute import getattribute cols = set(k for k,v in COLUMN_CHOICES) widths = set(k for k,v in COLUMN_WIDTHS_DATA) self.assertEquals(cols, widths) gs = self.__make_test_grad() for key in cols: # make sure each column returns *something* without error getattribute(gs, key)
def _generate_excel(response, columns, headers, grads): import xlwt book = xlwt.Workbook(encoding='utf-8') sheet = book.add_sheet('Search Results') hdrstyle = xlwt.easyxf( 'font: bold on; pattern: pattern solid, fore_colour grey25; align: horiz centre' ) evenstyle = xlwt.easyxf('pattern: back_colour gray40') oddstyle = xlwt.easyxf('pattern: pattern sparse_dots, fore_colour grey25') # header row sheet.write(0, 0, 'Graduate Student Search Results', xlwt.easyxf('font: bold on, height 320')) sheet.row(0).height = 400 for i, hdr in enumerate(headers): sheet.write(1, i, hdr, hdrstyle) # data rows for i, grad in enumerate(grads): style = [oddstyle, evenstyle][i % 2] for j, column in enumerate(columns): sheet.write(i + 2, j, getattribute(grad, column, html=False), style) # set column widths for i, c in enumerate(columns): wid = COLUMN_WIDTHS[c] sheet.col(i).width = wid count = len(grads) sheet.write(count + 4, 0, 'Number of students: %i' % (count)) sheet.write(count + 5, 0, 'Report generated: %s' % (datetime.datetime.now())) book.save(response)
def _generate_excel(response, columns, headers, grads): import xlwt book = xlwt.Workbook(encoding='utf-8') sheet = book.add_sheet('Search Results') hdrstyle = xlwt.easyxf('font: bold on; pattern: pattern solid, fore_colour grey25; align: horiz centre') evenstyle = xlwt.easyxf('pattern: back_colour gray40') oddstyle = xlwt.easyxf('pattern: pattern sparse_dots, fore_colour grey25') # header row sheet.write(0, 0, u'Graduate Student Search Results', xlwt.easyxf('font: bold on, height 320')) sheet.row(0).height = 400 for i,hdr in enumerate(headers): sheet.write(1, i, hdr, hdrstyle) # data rows for i,grad in enumerate(grads): style = [oddstyle, evenstyle][i%2] for j,column in enumerate(columns): sheet.write(i+2, j, getattribute(grad, column, html=False), style) # set column widths for i,c in enumerate(columns): wid = COLUMN_WIDTHS[c] sheet.col(i).width = wid count = len(grads) sheet.write(count+4, 0, 'Number of students: %i' % (count)) sheet.write(count+5, 0, 'Report generated: %s' % (datetime.datetime.now())) book.save(response)
def _generate_csv(response, columns, headers, grads): writer = csv.writer(response) writer.writerow(headers) for grad in grads: row = [] for column in columns: value = getattribute(grad, column, html=False) row.append(value) writer.writerow(row)
def _generate_csv(response, columns, headers, grads): writer = csv.writer(response) writer.writerow( headers ) for grad in grads: row = [] for column in columns: value = getattribute(grad, column, html=False) row.append(value) writer.writerow( row )