Skip to content

Commit

Permalink
fix: Date format when importing international timestamps (apache#25113)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina authored Aug 30, 2023
1 parent e642361 commit 00550d7
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 115 deletions.
229 changes: 114 additions & 115 deletions superset/templates/superset/form_view/csv_to_database_view/edit.html
Original file line number Diff line number Diff line change
@@ -1,142 +1,141 @@
{#
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
#}
{% extends "appbuilder/base.html" %}
{% import 'appbuilder/general/lib.html' as lib %}
{% import "superset/macros.html" as macros %}
{% set begin_sep_label = '<td class="col-sm-2" style="border-left: 0; border-top: 0;">' %}
{% set end_sep_label = '</td>' %}
{% set begin_sep_field = '<td style="border-right: 0; border-top: 0;">' %}
{% set end_sep_field = '</td>' %}
{% import 'superset/form_view/database_schemas_selector.html' as schemas_selector %}
{% import 'superset/form_view/csv_scripts.html' as csv_scripts %}
{% import 'superset/form_view/csv_macros.html' as csv_macros %}
{% block content %}
{{ lib.panel_begin(title, "edit") }}
{# Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with this work
for additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
applicable law or agreed to in writing, software distributed under the License
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License. #} {% extends
"appbuilder/base.html" %} {% import 'appbuilder/general/lib.html' as lib %} {%
import "superset/macros.html" as macros %} {% set begin_sep_label = '
<td class="col-sm-2" style="border-left: 0; border-top: 0">
' %} {% set end_sep_label = '
</td>
' %} {% set begin_sep_field = '
<td style="border-right: 0; border-top: 0">' %} {% set end_sep_field = '</td>
' %} {% import 'superset/form_view/database_schemas_selector.html' as
schemas_selector %} {% import 'superset/form_view/csv_scripts.html' as
csv_scripts %} {% import 'superset/form_view/csv_macros.html' as csv_macros %}
{% block content %} {{ lib.panel_begin(title, "edit") }}
<div id="Home" class="tab-pane active">
<form id="model_form" action="" method="post" enctype="multipart/form-data">
{{form.hidden_tag()}}
<div class="form-group">
<div class="col-md-12" style="padding: 0;">
<div class="col-md-12" style="padding: 0">
<table class="table table-bordered">
<tbody>
<tr>
{{ lib.render_field(form.csv_file, begin_sep_label, end_sep_label, begin_sep_field, end_sep_field) }}
{{ lib.render_field(form.csv_file, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.table_name, begin_sep_label, end_sep_label, begin_sep_field, end_sep_field) }}
{{ lib.render_field(form.table_name, begin_sep_label,
end_sep_label, begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.database, begin_sep_label, end_sep_label, begin_sep_field, end_sep_field) }}
{{ lib.render_field(form.database, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.schema, begin_sep_label, end_sep_label, begin_sep_field, end_sep_field) }}
{{ lib.render_field(form.schema, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ csv_macros.render_delimiter_field(form.delimiter, begin_sep_label, end_sep_label, begin_sep_field, end_sep_field) }}
{{ csv_macros.render_delimiter_field(form.delimiter,
begin_sep_label, end_sep_label, begin_sep_field, end_sep_field) }}
</tr>
</tbody>
</table>
</div>
</div>
{% call csv_macros.render_collapsable_form_group("accordion1", "File Settings") %}
<tr>
{{ lib.render_field(form.if_exists, begin_sep_label, end_sep_label, begin_sep_field,
end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.skip_initial_space, begin_sep_label, end_sep_label, begin_sep_field,
end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.skip_blank_lines, begin_sep_label, end_sep_label, begin_sep_field,
end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.parse_dates, begin_sep_label, end_sep_label, begin_sep_field,
end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.infer_datetime_format, begin_sep_label, end_sep_label, begin_sep_field,
end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.decimal, begin_sep_label, end_sep_label, begin_sep_field,
end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.null_values, begin_sep_label, end_sep_label, begin_sep_field,
end_sep_field) }}
</tr>
{% endcall %}
{% call csv_macros.render_collapsable_form_group("accordion2", "Columns") %}
<tr>
{{ lib.render_field(form.index_col, begin_sep_label, end_sep_label, begin_sep_field,
end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.dataframe_index, begin_sep_label, end_sep_label, begin_sep_field,
end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.index_label, begin_sep_label, end_sep_label, begin_sep_field,
end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.use_cols, begin_sep_label, end_sep_label, begin_sep_field,
end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.overwrite_duplicate, begin_sep_label, end_sep_label, begin_sep_field,
end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.dtype, begin_sep_label, end_sep_label, begin_sep_field,
end_sep_field) }}
</tr>
{% endcall %}
{% call csv_macros.render_collapsable_form_group("accordion3", "Rows") %}
<tr>
{{ lib.render_field(form.header, begin_sep_label, end_sep_label, begin_sep_field, end_sep_field)
}}
</tr>
<tr>
{{ lib.render_field(form.nrows, begin_sep_label, end_sep_label, begin_sep_field, end_sep_field)
}}
</tr>
<tr>
{{ lib.render_field(form.skiprows, begin_sep_label, end_sep_label, begin_sep_field,
end_sep_field) }}
</tr>
{% call csv_macros.render_collapsable_form_group("accordion1", "File
Settings") %}
<tr>
{{ lib.render_field(form.if_exists, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.skip_initial_space, begin_sep_label,
end_sep_label, begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.skip_blank_lines, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.parse_dates, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.infer_datetime_format, begin_sep_label,
end_sep_label, begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.day_first, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.decimal, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.null_values, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
{% endcall %} {% call csv_macros.render_collapsable_form_group("accordion2",
"Columns") %}
<tr>
{{ lib.render_field(form.index_col, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.dataframe_index, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.index_label, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.use_cols, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.overwrite_duplicate, begin_sep_label,
end_sep_label, begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.dtype, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
{% endcall %} {% call csv_macros.render_collapsable_form_group("accordion3",
"Rows") %}
<tr>
{{ lib.render_field(form.header, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.nrows, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
<tr>
{{ lib.render_field(form.skiprows, begin_sep_label, end_sep_label,
begin_sep_field, end_sep_field) }}
</tr>
{% endcall %}
<div class="form-group">
<div class="col-xs-12" style="padding: 0;">
<div class="col-xs-12" style="padding: 0">
{{ lib.render_form_controls() }}
</div>
</div>
</form>
</div>
{% endblock %}
{% block add_tail_js %}
<script src="{{url_for('appbuilder.static',filename='js/ab_keep_tab.js')}}" nonce="{{ macros.get_nonce() }}"></script>
{% endblock %}
{% block tail_js %}
{{ super() }}
{{ schemas_selector }}
{{ csv_scripts }}
{% endblock %}
{% endblock %} {% block add_tail_js %}
<script
src="{{url_for('appbuilder.static',filename='js/ab_keep_tab.js')}}"
nonce="{{ macros.get_nonce() }}"
></script>
{% endblock %} {% block tail_js %} {{ super() }} {{ schemas_selector }} {{
csv_scripts }} {% endblock %}
4 changes: 4 additions & 0 deletions superset/views/database/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ class CsvToDatabaseForm(UploadToDatabaseForm):
_("Interpret Datetime Format Automatically"),
description=_("Interpret the datetime format automatically"),
)
day_first = BooleanField(
_("Day First"),
description=_("DD/MM format dates, international and European format"),
)
decimal = StringField(
_("Decimal Character"),
default=".",
Expand Down
2 changes: 2 additions & 0 deletions superset/views/database/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def form_get(self, form: CsvToDatabaseForm) -> None:
form.skip_initial_space.data = False
form.skip_blank_lines.data = True
form.infer_datetime_format.data = True
form.day_first.data = False
form.decimal.data = "."
form.if_exists.data = "fail"

Expand Down Expand Up @@ -199,6 +200,7 @@ def form_post(self, form: CsvToDatabaseForm) -> Response:
header=form.header.data if form.header.data else 0,
index_col=form.index_col.data,
infer_datetime_format=form.infer_datetime_format.data,
dayfirst=form.day_first.data,
iterator=True,
keep_default_na=not form.null_values.data,
usecols=form.use_cols.data if form.use_cols.data else None,
Expand Down

0 comments on commit 00550d7

Please sign in to comment.