Skip to content

Commit 887d18e

Browse files
authored
fix import/update excel date preview and fix import/update match date column (#842)
1 parent c5e338e commit 887d18e

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

dtable_events/dtable_io/big_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from dtable_events.dtable_io.excel import parse_row, write_xls_with_type, TEMP_EXPORT_VIEW_DIR, IMAGE_TMP_DIR
88
from dtable_events.dtable_io.utils import get_related_nicknames_from_dtable, get_metadata_from_dtable_server, \
99
escape_sheet_name
10-
from dtable_events.utils import get_location_tree_json, gen_random_option, format_date
10+
from dtable_events.utils import get_location_tree_json, gen_random_option, format_date_in_query
1111
from dtable_events.utils.constants import ColumnTypes
1212
from dtable_events.app.config import INNER_DTABLE_DB_URL, BIG_DATA_ROW_IMPORT_LIMIT, BIG_DATA_ROW_UPDATE_LIMIT, \
1313
ARCHIVE_VIEW_EXPORT_ROW_LIMIT, APP_TABLE_EXPORT_EXCEL_ROW_LIMIT, INNER_DTABLE_SERVER_URL
@@ -104,7 +104,7 @@ def handle_excel_row_datas(db_api, table_name, excel_row_datas, ref_cols, column
104104
if column_name_type_map.get(col) and column_name_type_map.get(col) == ColumnTypes.DATE:
105105
pre_format_date_str = base_row.get(col).replace('T', ' ')
106106
pre_format_date_str = pre_format_date_str.split('+' if '+' in pre_format_date_str else '-')[0]
107-
base_ref_data[col] = format_date(pre_format_date_str, column_name_data_map.get(col).get('format'))
107+
base_ref_data[col] = format_date_in_query(pre_format_date_str, column_name_data_map.get(col).get('format'))
108108
if base_ref_data and excel_ref_data and base_ref_data == excel_ref_data:
109109
rows_for_update.append({
110110
"row_id": base_row.get('_id'),
@@ -374,7 +374,7 @@ def update_excel_to_db(
374374
pop_col_lists.append(col_name)
375375
continue
376376
elif col_type == ColumnTypes.DATE and col_data:
377-
row_data[col_name] = format_date(str(value), col_data.get('format'))
377+
row_data[col_name] = format_date_in_query(str(value), col_data.get('format'))
378378

379379
row_data1 = deepcopy(row_data)
380380
for col_name in pop_col_lists:

dtable_events/dtable_io/excel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from copy import deepcopy
1111
from datetime import datetime, time
1212
from dtable_events.app.config import EXPORT2EXCEL_DEFAULT_STRING, TIME_ZONE, INNER_DTABLE_DB_URL, INNER_DTABLE_SERVER_URL
13-
from dtable_events.utils import utc_to_tz, gen_random_option, format_date
13+
from dtable_events.utils import utc_to_tz, gen_random_option, format_date_in_query
1414
from dtable_events.utils.constants import ColumnTypes, FormulaResultType
1515
from dtable_events.utils.geo_location_parser import parse_geolocation_from_tree
1616
from dtable_events.utils.dtable_db_api import DTableDBAPI
@@ -749,7 +749,7 @@ def get_dtable_row_data(dtable_rows, key_columns, excel_col_name_to_type, excel_
749749
key_cols_value = []
750750
for col in key_columns:
751751
if col in row and excel_col_name_to_type.get(col) and excel_col_name_to_type.get(col) == ColumnTypes.DATE:
752-
row[col] = format_date(row[col], excel_col_name_to_data.get(col).get('format'))
752+
row[col] = format_date_in_query(row[col], excel_col_name_to_data.get(col).get('format'))
753753
key_cols_value.append(str(get_cell_value(row, col, excel_col_name_to_type)))
754754
key = str(hash('-'.join(key_cols_value)))
755755
if dtable_row_data.get(key):
@@ -1117,7 +1117,7 @@ def parse_row(column_type, cell_value, name_to_email, location_tree=None, column
11171117
return parse_duration(cell_value)
11181118
elif column_type == 'date':
11191119
if column_data:
1120-
return format_date(str(cell_value), column_data.get('format'))
1120+
return format_date_in_query(str(cell_value), column_data.get('format'))
11211121
return str(cell_value)
11221122
elif column_type == 'long-text':
11231123
return parse_long_text(cell_value)

dtable_events/utils/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,20 @@ def format_date(date, format):
210210
return value
211211

212212

213+
def format_date_in_query(date, format):
214+
try:
215+
timestamp = parser.parse(date.strip()).timestamp()
216+
except:
217+
return ''
218+
timestamp = round(timestamp, 0)
219+
datetime_obj = datetime.fromtimestamp(timestamp)
220+
if 'HH:mm' in format:
221+
value = datetime_obj.strftime('%Y-%m-%d %H:%M')
222+
else:
223+
value = datetime_obj.strftime('%Y-%m-%d')
224+
return value
225+
226+
213227
def uuid_str_to_36_chars(dtable_uuid):
214228
if len(dtable_uuid) == 32:
215229
return str(uuid.UUID(dtable_uuid))

0 commit comments

Comments
 (0)