def _export_table(self, export_sheet_name, headers, formatted_rows, total_row=None): def _unformat_row(row): return [ col.get("sort_key", col) if isinstance(col, dict) else col for col in row ] table = headers.as_export_table table.insert(0, [ SQLLocation.objects.get( location_id=self.report_config['location_id']).name ]) rows = [_unformat_row(row) for row in formatted_rows] # Removing html icon tag from MOS column for row in rows: row[1] = GenericTabularReport._strip_tags(row[1]) replace = '' for k, v in enumerate(table[1]): if v != ' ': replace = v else: table[1][k] = replace table.extend(rows) if total_row: table.append(_unformat_row(total_row)) return [export_sheet_name, self._report_info + table]
def test_strip_tags_expected_fail(self): """ _strip_tags should not strip strings inside angle brackets, but does """ value = '1 < 8 > 2' value = GenericTabularReport._strip_tags(value) self.assertEqual(value, '1 < 8 > 2')
def test_strip_tags_html_bytestring(self): """ _strip_tags should strip HTML tags """ value = '<blink>182</blink>' value = GenericTabularReport._strip_tags(value) self.assertEqual(value, '182')
def test_strip_tags_html_unicode(self): """ _strip_tags should strip HTML tags from Unicode """ value = u'<blink>182</blink>' value = GenericTabularReport._strip_tags(value) self.assertEqual(value, u'182')
def test_strip_tags_passthru(self): """ _strip_tags should allow non-basestring values to pass through """ value = {'blink': 182} value = GenericTabularReport._strip_tags(value) self.assertEqual(value, {'blink': 182})
def _export_table(self, export_sheet_name, headers, formatted_rows, total_row=None): def _unformat_row(row): return [ col.get("sort_key", col) if isinstance(col, dict) else col for col in row ] table = headers.as_export_table rows = [_unformat_row(row) for row in formatted_rows] replace = '' for row in rows: for index, value in enumerate(row): row[index] = GenericTabularReport._strip_tags(value) # make headers and subheaders consistent for k, v in enumerate(table[0]): if v != ' ': replace = v else: table[0][k] = replace table.extend(rows) if total_row: table.append(_unformat_row(total_row)) return [export_sheet_name, table]
def _export(self, export_sheet_name, headers, formatted_rows, total_row=None): def _unformat_row(row): return [ col.get("sort_key", col) if isinstance(col, dict) else col for col in row ] table = headers.as_export_table rows = [_unformat_row(row) for row in formatted_rows] for row in rows: row[0] = GenericTabularReport._strip_tags(row[0]) replace = '' for k, v in enumerate(table[0]): if v != ' ': replace = v else: table[0][k] = replace table.extend(rows) if total_row: table.append(_unformat_row(total_row)) return [export_sheet_name, self._report_info + table]
def _export(self, export_sheet_name, headers, formatted_rows, total_row=None): def _unformat_row(row): return [col.get("sort_key", col) if isinstance(col, dict) else col for col in row] table = headers.as_export_table rows = [_unformat_row(row) for row in formatted_rows] for row in rows: row[0] = GenericTabularReport._strip_tags(row[0]) replace = '' for k, v in enumerate(table[0]): if v != ' ': replace = v else: table[0][k] = replace table.extend(rows) return [export_sheet_name, self._report_info + table]
def _export_table(self, export_sheet_name, headers, formatted_rows, total_row=None): def _unformat_row(row): return [col.get("sort_key", col) if isinstance(col, dict) else col for col in row] table = headers.as_export_table rows = [_unformat_row(row) for row in formatted_rows] # Removing html icon tag from MOS column for row in rows: row[1] = GenericTabularReport._strip_tags(row[1]) replace = '' for k, v in enumerate(table[0]): if v != ' ': replace = v else: table[0][k] = replace table.extend(rows) if total_row: table.append(_unformat_row(total_row)) return [export_sheet_name, table]
def _export_table(self, export_sheet_name, headers, formatted_rows, total_row=None): def _unformat_row(row): return [col.get("sort_key", col) if isinstance(col, dict) else col for col in row] table = headers.as_export_table table.insert(0, [SQLLocation.objects.get(location_id=self.report_config['location_id']).name]) rows = [_unformat_row(row) for row in formatted_rows] # Removing html icon tag from MOS column for row in rows: row[1] = GenericTabularReport._strip_tags(row[1]) replace = '' for k, v in enumerate(table[1]): if v != ' ': replace = v else: table[1][k] = replace table.extend(rows) if total_row: table.append(_unformat_row(total_row)) return [export_sheet_name, self._report_info + table]
def _export_table(self, export_sheet_name, headers, formatted_rows, total_row=None): def _unformat_row(row): return [col.get("sort_key", col) if isinstance(col, dict) else col for col in row] table = headers.as_export_table rows = [_unformat_row(row) for row in formatted_rows] replace = '' for row in rows: for index, value in enumerate(row): row[index] = GenericTabularReport._strip_tags(value) # make headers and subheaders consistent for k, v in enumerate(table[0]): if v != ' ': replace = v else: table[0][k] = replace table.extend(rows) if total_row: table.append(_unformat_row(total_row)) return [export_sheet_name, table]