You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@superset.apache.org by gi...@git.apache.org on 2017/10/06 00:37:10 UTC

[GitHub] timifasubaa commented on a change in pull request #3533: Latest import csv

timifasubaa commented on a change in pull request #3533: Latest import csv
URL: https://github.com/apache/incubator-superset/pull/3533#discussion_r143089233
 
 

 ##########
 File path: superset/csvform.py
 ##########
 @@ -0,0 +1,205 @@
+"""Contains the logic to create cohesive forms on the explore view"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
+from flask_babel import lazy_gettext as _
+
+from flask_appbuilder.fieldwidgets import BS3TextFieldWidget
+from flask_appbuilder.forms import DynamicForm
+
+from flask_wtf.file import FileField, FileAllowed, FileRequired
+from wtforms import (
+    SelectField, IntegerField, StringField)
+from wtforms.validators import DataRequired, Optional, NumberRange
+
+from superset import app, db
+import superset.models.core as models
+import logging
+
+
+config = app.config
+
+class CsvToDatabaseForm(DynamicForm):
+    # These are the fields exposed by Pandas read_csv()
+
+    # TODO: Add a must be alphanumeric, not numeric validator.
+    name = StringField(_('Table Name'),
+                       description=_('Name of table to be created '
+                                     'from csv data.'),
+                       validators=[DataRequired()],
+                       widget=BS3TextFieldWidget())
+    csv_file = FileField(_('CSV File'),
+                         description=_('Select a CSV file to be '
+                                       'uploaded to a database.'),
+                         validators=[FileRequired(),
+                                     FileAllowed(['csv'],
+                                                 _('CSV Files '
+                                                   'Only!'))])
+    all_datasources = []
+    try:
+      all_datasources = db.session.query(models.Database.sqlalchemy_uri, models.Database.database_name).all()
+    except Exception as e:
+      logging.info("Exception retreiving dbs: {}".format(e))
+
+    con = SelectField(_('Database URI'),
+                     description=_('URI of database in which to '
+                                    'add above table.'),
+                     validators=[DataRequired()],
+                     choices=all_datasources
+                       )
+    if_exists = SelectField(_('Table Exists'),
+                            description=_('If table exists do one '
 
 Review comment:
   Fixed
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services