Beispiel #1
0
    def get(self):
        #
        # it is import not to put 'db' into this dict to indicate this is add_data_source
        base_navigation_dict = {
            'selected_menu': 'datasources',
            'self.request.path': self.request.path,
            'dbrs': si_app.get_data_source_rs(),
            'plugin_name_list': si_app.get_plugin_name_list(),
            'selected_add_data_source': True,
            'input_ds_param': True,
            'selected_schema_name': '__add_data_source__',
        }
        ds_type = self.get_argument('ds_type', default=None)

        if ds_type is None:
            ds_type = si_app.get_plugin_name_list()[
                0]  # simply choose first available plugin

        base_navigation_dict['input_db_type'] = ds_type
        plugin_info = si_app.get_plugin_info(p_plugin_name=ds_type)
        base_navigation_dict['input_ds_param'] = json.loads(
            plugin_info.ds_param)

        #self.render("database_summary.html",
        #            base_navigation_dict=base_navigation_dict,
        #              db=None,tabrs=None)
        self.write(
            self.render_template(
                'database_summary.html',
                base_navigation_dict=base_navigation_dict,
            ))
Beispiel #2
0
    def post(self):
        ds_dict = {}
        ds_dict['ds_name'] = self.get_argument('ds_name')
        ds_dict['ds_type'] = self.get_argument('ds_type')
        ds_dict['ds_desc'] = self.get_argument('ds_desc')

        ds_dict['ds_param'] = {}
        ds_plugin_info = si_app.get_plugin_info(
            p_plugin_name=ds_dict['ds_type'])
        param_name_dict = json.loads(ds_plugin_info.ds_param)
        for param_name in param_name_dict.keys():
            if param_name_dict[param_name]['type'] == 'Boolean':
                ds_dict['ds_param'][param_name] = self.get_argument(
                    'ds_param.' + param_name, default='off')
            else:
                ds_dict['ds_param'][param_name] = self.get_argument(
                    'ds_param.' + param_name)

        db = si_app.update_data_soruce(ds_dict)

        dbrs = si_app.get_data_source_rs()

        result_message = {
            'message_type':
            'info',
            'message_title':
            'Success',
            'message_body':
            'The data source %s is updated.' % (str(ds_dict['ds_name']))
        }

        base_navigation_dict = {
            'selected_menu': 'database',
            'dbrs': dbrs,
            'selected_add_data_source': False,
            'selected_schema_name': ds_dict['ds_name'],
            'plugin_name_list': si_app.get_plugin_name_list(),
            'message': result_message,
            'self.request.path': self.request.path,
            'db': db.to_dict(
            ),  # When 'db' is available, it is treated as show_data_source
        }

        base_navigation_dict['input_db_type'] = db.ds_type
        plugin_info = si_app.get_plugin_info(p_plugin_name=db.ds_type)
        base_navigation_dict['input_ds_param'] = json.loads(
            plugin_info.ds_param)

        #self.render("database_summary.html",
        #            base_navigation_dict=base_navigation_dict, dbrs=dbrs, db = None,tabrs=None)
        self.write(
            self.render_template(
                'database_summary.html',
                base_navigation_dict=base_navigation_dict,
            ))
Beispiel #3
0
    def get(self):
        # self.write("Hello, world")
        dbrs = si_app.get_data_source_rs()

        ds_count = dbrs.count()
        base_navigation_dict = {
            'selected_menu': 'overview',
            'dbrs': dbrs,
            'plugin_list': si_app.get_plugin_list(),
            'ds_count': str(ds_count),
        }

        self.write(
            self.render_template(
                'overview.html',
                base_navigation_dict=base_navigation_dict,
            ))
Beispiel #4
0
    def post(self):

        q = self.get_argument('q')
        res = si_app.global_whoosh_search(q)
        dbrs = si_app.get_data_source_rs()

        base_navigation_dict = {
            'selected_menu': 'search',
            'dbrs': dbrs,
            'selected_schema_name': '',
            'q': q,
            'search_result': res,
        }
        self.write(
            self.render_template(
                'global_search_result.html',
                base_navigation_dict=base_navigation_dict,
            ))
Beispiel #5
0
    def post(self):
        ds_name = self.get_argument('ds_name')
        ds_dict = si_app.get_data_source_dict(ds_name=ds_name)
        ds_dict['delete_reflected_database_automatic'] = self.get_argument(
            'delete_reflected_database_automatic', default=None)

        result_message = si_app.delete_data_soruce(ds_dict)
        dbrs = si_app.get_data_source_rs()
        base_navigation_dict = {
            'selected_menu': 'database',
            'self.request.path': self.request.path,
            'dbrs': dbrs,
            'selected_add_data_source': True,
            'plugin_name_list': si_app.get_plugin_name_list(),
            'selected_schema_name': ds_dict['ds_name'],
            'message': result_message
        }
        if result_message['message_title'] == 'Error':
            #session = create_session(bind=engine)
            #dbrs1 = session.query(MDatasource).filter_by(ds_name = ds_dict['ds_name'])
            #db = dbrs1.first()
            base_navigation_dict['db'] = ds_dict
            base_navigation_dict[
                'tabrs'] = si_app.get_table_list_for_data_source_rs(
                    param_ds_name=ds_dict['ds_name'])
            base_navigation_dict['input_db_type'] = ds_dict['ds_type']
            plugin_info = si_app.get_plugin_info(
                p_plugin_name=ds_dict['ds_type'])
            base_navigation_dict['input_ds_param'] = json.loads(
                plugin_info.ds_param)

            #self.render("database_summary.html",
            #            base_navigation_dict=base_navigation_dict)

            self.write(
                self.render_template(
                    'database_summary.html',
                    base_navigation_dict=base_navigation_dict,
                ))

        self.redirect('./overview')
Beispiel #6
0
    def get(self):
        q = ''
        res = []
        dbrs = si_app.get_data_source_rs()

        base_navigation_dict = {
            'selected_menu': 'search',
            'dbrs': dbrs,
            'selected_schema_name': '',
            'q': q,
            'search_result': res,
        }
        '''
        self.render("global_search_result.html",
                    dbrs=dbrs,
                    q=q,
                    base_navigation_dict=base_navigation_dict,
                    search_result = res )
        '''
        self.write(
            self.render_template(
                'global_search_result.html',
                base_navigation_dict=base_navigation_dict,
            ))
Beispiel #7
0
    def post(self):
        ds_dict = {}
        ds_dict['ds_name'] = self.get_argument('ds_name')
        ds_dict['ds_desc'] = self.get_argument('ds_desc')
        ds_dict['ds_type'] = self.get_argument('ds_type')

        ds_dict['reflect_database_automatic'] = self.get_argument(
            'reflect_database_automatic', default='off')

        ds_dict['ds_param'] = {}
        ds_plugin_info = si_app.get_plugin_info(
            p_plugin_name=ds_dict['ds_type'])
        param_name_dict = json.loads(ds_plugin_info.ds_param)
        for param_name in param_name_dict.keys():
            if param_name_dict[param_name]['type'] == 'Boolean':
                ds_dict['ds_param'][param_name] = self.get_argument(
                    'ds_param.' + param_name, default=False)
            else:
                ds_dict['ds_param'][param_name] = self.get_argument(
                    'ds_param.' + param_name)

        try:
            si_app.add_data_soruce(ds_dict)
            if (ds_dict['reflect_database_automatic'] == 'on'):
                si_pm.reflect_db(ds_dict['ds_name'])

            #Info = {'result': 'ok', 'message': 'A new data source is added.'}
            self.redirect('./database_summary?ds_name=' + ds_dict['ds_name'])
        except Exception as e:
            si_app.logger.error('failed to add data source!')
            si_app.logger.error(e)
            #Info = {'result': 'ok', 'message': 'A new data source is added.'}
            dbrs = si_app.get_data_source_rs()
            result_message = {
                'message_type':
                'danger',
                'message_title':
                'Error',
                'message_body':
                'Failed to add data source: %s! The error was: %s' %
                (str(ds_dict['ds_name']), str(e))
            }

            base_navigation_dict = {
                'selected_menu': 'database',
                'self.request.path': self.request.path,
                'dbrs': dbrs,
                'selected_add_data_source': True,
                'plugin_name_list': si_app.get_plugin_name_list(),
                'selected_schema_name': ds_dict['ds_name'],
                'message': result_message,
                'db': ds_dict,
            }
            base_navigation_dict['input_db_type'] = ds_dict['ds_type']
            plugin_info = si_app.get_plugin_info(
                p_plugin_name=ds_dict['ds_type'])
            base_navigation_dict['input_ds_param'] = json.loads(
                plugin_info.ds_param)

            #self.render("database_summary.html",
            #            base_navigation_dict=base_navigation_dict)
            self.write(
                self.render_template(
                    'database_summary.html',
                    base_navigation_dict=base_navigation_dict,
                ))
Beispiel #8
0
    def get(self):
        # self.write("Hello, world")
        # param_db_name = self.get_argument("table_group_name", None)
        # session = create_session(bind=engine)
        print(self.request.path)
        param_ds_name = self.get_argument("ds_name", None)
        if param_ds_name is None:
            si_app.logger.warn('error: no data source name is given (ds_name)')
            result_message = {
                'message_type': 'danger',
                'message_title': 'Error',
                'message_body': 'No data source name is given (ds_name)'
            }

            base_navigation_dict = {
                'selected_menu': 'datasources',
                'dbrs':
                si_app.get_data_source_rs(),  # session.query(MDatasource),
                'error': 'error: no schema name is given',
                'selected_add_data_source': False,
                'message': result_message,
                'db': None,
                'self.request.path': self.request.path,
            }
            # self.rend
            self.write(
                self.render_template(
                    'database_summary.html',
                    base_navigation_dict=base_navigation_dict,
                ))

        #dbrs1 = session.query(MDatasource).filter_by(ds_name = param_ds_name )
        # db = dbrs1.first()

        # 20180120, changed db from MDatasoruce to ds_dict.
        db = si_app.get_data_source_dict(ds_name=param_ds_name)
        if db is None:
            print('')
            si_app.logger.warn('error: did not find database' + param_ds_name +
                               ' after creation.')
            result_message = {
                'message_type': 'danger',
                'message_title': 'Error',
                'message_body': 'error: did not find database' + param_ds_name
            }

            base_navigation_dict = {
                'selected_menu': 'overview',
                'dbrs':
                si_app.get_data_source_rs(),  # session.query(MDatasource),
                'error': 'error: no schema name is given',
                'selected_add_data_source': False,
                'message': result_message,
                'self.request.path': self.request.path,
                'plugin_list': si_app.get_plugin_list(),
            }

            self.write(
                self.render_template(
                    'database_summary.html',
                    base_navigation_dict=base_navigation_dict,
                ))

        dbrs = si_app.get_data_source_rs()
        tabrs = si_app.get_table_list_for_data_source_rs(
            param_ds_name=param_ds_name)

        base_navigation_dict = {
            'selected_menu': 'datasources',
            'selected_add_data_source': False,
            'dbrs': dbrs,
            'selected_schema_name': param_ds_name,
            'db': db,
            'tabrs': tabrs,
            'self.request.path': self.request.path,
            'plugin_name_list': si_app.get_plugin_name_list(),
        }

        base_navigation_dict['input_db_type'] = db['ds_type']
        plugin_info = si_app.get_plugin_info(p_plugin_name=db['ds_type'])
        base_navigation_dict['input_ds_param'] = json.loads(
            plugin_info.ds_param)

        self.write(
            self.render_template(
                'database_summary.html',
                base_navigation_dict=base_navigation_dict,
            ))