Эх сурвалжийг харах

HUE-8089 [core] Update Excel hyperlinking to be compatible with Python 2.6

Romain Rigaux 7 жил өмнө
parent
commit
f9cfc8a542

+ 1 - 1
desktop/core/src/desktop/lib/export_csvxls.py

@@ -47,7 +47,7 @@ def encode_row(row, encoding=None, make_excel_links=False):
     if isinstance(cell, six.string_types):
       cell = re.sub(ILLEGAL_CHARS, '?', cell)
       if make_excel_links:
-        cell = re.sub('(https?://.+)', r'=HYPERLINK("\1")', cell, flags=re.IGNORECASE)
+        cell = re.compile('(https?://.+)', re.IGNORECASE).sub(r'=HYPERLINK("\1")', cell)
     cell = nullify(cell)
     if not isinstance(cell, numbers.Number):
       cell = smart_str(cell, encoding or i18n.get_site_encoding(), strings_only=True, errors='replace')

+ 3 - 3
desktop/core/src/desktop/lib/test_export_csvxls.py

@@ -29,7 +29,7 @@ def content_generator(header, data):
 
 def test_export_csv():
   headers = ["x", "y"]
-  data = [ ["1", "2"], ["3", "4"], ["5,6", "7"], [None, None] ]
+  data = [ ["1", "2"], ["3", "4"], ["5,6", "7"], [None, None], ["http://gethue.com", "http://gethue.com"] ]
 
   # Check CSV
   generator = create_generator(content_generator(headers, data), "csv")
@@ -42,7 +42,7 @@ def test_export_csv():
 
 def test_export_xls():
   headers = ["x", "y"]
-  data = [ ["1", "2"], ["3", "4"], ["5,6", "7"], [None, None] ]
+  data = [ ["1", "2"], ["3", "4"], ["5,6", "7"], [None, None], ["http://gethue.com", "http://gethue.com"] ]
   sheet = [headers] + data
 
   # Check XLS
@@ -50,7 +50,7 @@ def test_export_xls():
   response = make_response(generator, "xls", "foo")
   assert_equal("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", response["content-type"])
 
-  expected_data = [[cell is not None and cell or "NULL" for cell in row] for row in sheet]
+  expected_data = [[cell is not None and cell.replace("http://gethue.com", '=HYPERLINK("http://gethue.com")') or "NULL" for cell in row] for row in sheet]
   sheet_data = _read_xls_sheet_data(response)
 
   assert_equal(expected_data, sheet_data)