Skip to content

Commit

Permalink
File upload:
Browse files Browse the repository at this point in the history
- Change forms fileds names for columnar and excel form views so they both use the same database DOM element as CSV form.
- Update our tests and the places where columnar and excel upload where using the not very descriptive "con" field
  • Loading branch information
Antonio-RiveroMartnez committed Nov 28, 2022
1 parent 435926b commit 37a05f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions superset/views/database/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class ExcelToDatabaseForm(UploadToDatabaseForm):
widget=BS3TextFieldWidget(),
)

con = QuerySelectField(
database = QuerySelectField(
_("Database"),
query_factory=UploadToDatabaseForm.file_allowed_dbs,
get_pk=lambda a: a.id,
Expand Down Expand Up @@ -424,7 +424,7 @@ class ColumnarToDatabaseForm(UploadToDatabaseForm):
],
)

con = QuerySelectField(
database = QuerySelectField(
_("Database"),
query_factory=UploadToDatabaseForm.file_allowed_dbs,
get_pk=lambda a: a.id,
Expand Down
12 changes: 6 additions & 6 deletions superset/views/database/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def form_get(self, form: ExcelToDatabaseForm) -> None:
form.sheet_name.data = ""

def form_post(self, form: ExcelToDatabaseForm) -> Response:
database = form.con.data
database = form.database.data
excel_table = Table(table=form.name.data, schema=form.schema.data)

if not schema_allows_file_upload(database, excel_table.schema):
Expand Down Expand Up @@ -301,7 +301,7 @@ def form_post(self, form: ExcelToDatabaseForm) -> Response:

database = (
db.session.query(models.Database)
.filter_by(id=form.data.get("con").data.get("id"))
.filter_by(id=form.data.get("database").data.get("id"))
.one()
)

Expand Down Expand Up @@ -378,7 +378,7 @@ def form_post(self, form: ExcelToDatabaseForm) -> Response:
flash(message, "info")
event_logger.log_with_context(
action="successful_excel_upload",
database=form.con.data.name,
database=form.database.data.name,
schema=form.schema.data,
table=form.name.data,
)
Expand All @@ -397,7 +397,7 @@ def form_get(self, form: ColumnarToDatabaseForm) -> None:
def form_post( # pylint: disable=too-many-locals
self, form: ColumnarToDatabaseForm
) -> Response:
database = form.con.data
database = form.database.data
columnar_table = Table(table=form.name.data, schema=form.schema.data)
files = form.columnar_file.data
file_type = {file.filename.split(".")[-1] for file in files}
Expand Down Expand Up @@ -442,7 +442,7 @@ def form_post( # pylint: disable=too-many-locals

database = (
db.session.query(models.Database)
.filter_by(id=form.data.get("con").data.get("id"))
.filter_by(id=form.data.get("database").data.get("id"))
.one()
)

Expand Down Expand Up @@ -519,7 +519,7 @@ def form_post( # pylint: disable=too-many-locals
flash(message, "info")
event_logger.log_with_context(
action="successful_columnar_upload",
database=form.con.data.name,
database=form.database.data.name,
schema=form.schema.data,
table=form.name.data,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/csv_upload_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def upload_excel(
form_data = {
"excel_file": open(filename, "rb"),
"name": table_name,
"con": excel_upload_db_id,
"database": excel_upload_db_id,
"sheet_name": "Sheet1",
"if_exists": "fail",
"index_label": "test_label",
Expand All @@ -165,7 +165,7 @@ def upload_columnar(
form_data = {
"columnar_file": open(filename, "rb"),
"name": table_name,
"con": columnar_upload_db_id,
"database": columnar_upload_db_id,
"if_exists": "fail",
"index_label": "test_label",
}
Expand Down

0 comments on commit 37a05f6

Please sign in to comment.