Example #1
0
 def get(self, request, *args, **kwargs):
     connection = kwargs.get('connection')
     if connection not in connections:
         raise Http404
     schema = schema_info(connection)
     if schema is not None:
         return render(None, 'explorer/schema.html', {'schema': schema_info(connection)})
     else:
         return render(None, 'explorer/schema_building.html')
Example #2
0
 def get(self, request, *args, **kwargs):
     connection = kwargs.get('connection')
     if connection not in connections:
         raise Http404
     schema = schema_info(connection)
     if schema:
         return render_to_response('explorer/schema.html',
                                   {'schema': schema_info(connection)})
     else:
         return render_to_response('explorer/schema_building.html')
Example #3
0
 def get(self, request, *args, **kwargs):
     connection = kwargs.get('connection')
     if connection not in connections:
         connection = app_settings.EXPLORER_DEFAULT_CONNECTION
     schema = schema_info(connection)
     if schema:
         return render_to_response('explorer/schema.html',
                                   {'schema': schema_info(connection)})
     else:
         return render_to_response('explorer/schema_building.html')
Example #4
0
    def get_model(self):
        schema = self.kwargs['schema']
        table = self.kwargs['table']

        columns = schema_info(self.kwargs['connection'], schema, table)
        table_name = f'"{schema}"."{table}"'

        try:
            model = ModelSchema.objects.get(name=table_name)
        except ModelSchema.DoesNotExist:
            model = ModelSchema.objects.create(name=table_name)

        for column in columns:
            # Django automatically adds a field called id to all models if a primary key isn't
            # specified so we need to skip adding this to the dynamic model
            if column.name == 'id':
                continue
            try:
                field = FieldSchema.objects.get(name=column.name)
            except FieldSchema.DoesNotExist:
                field = FieldSchema.objects.create(
                    name=column.name, data_type=self.COLUMN_MAPPING[column.type]
                )

            try:
                model.add_field(field)
            except Exception:
                pass

        Model = model.as_model()
        Model.objects = Model.objects.using(self.kwargs['connection'])
        Model._meta.db_table = table_name

        return Model
 def test_app_inclusion_list_excluded(self):
     # Inclusion list "wins"
     schema._get_includes = lambda: ('explorer_', )
     schema._get_excludes = lambda: ('explorer_', )
     res = schema.schema_info(get_connection())
     tables = [x[0] for x in res]
     self.assertIn('explorer_query', tables)
 def test_app_inclusion_list_excluded(self, mocked_excludes, mocked_includes):
     # Inclusion list "wins"
     mocked_includes.return_value = ('explorer_',)
     mocked_excludes.return_value = ('explorer_',)
     res = schema.schema_info(CONN)
     tables = [x[0] for x in res]
     self.assertIn('explorer_query', tables)
 def test_schema_info_returns_valid_data(self, mocked_excludes, mocked_includes):
     mocked_includes.return_value = None
     mocked_excludes.return_value = []
     res = schema.schema_info(CONN)
     assert mocked_includes.called  # sanity check: ensure patch worked
     tables = [x[0] for x in res]
     self.assertIn('explorer_query', tables)
 def test_app_inclusion_list(self, mocked_excludes, mocked_includes):
     mocked_includes.return_value = ('auth_',)
     mocked_excludes.return_value = []
     res = schema.schema_info(CONN)
     tables = [x[0] for x in res]
     self.assertNotIn('explorer_query', tables)
     self.assertIn('auth_user', tables)
 def test_app_inclusion_list_excluded(self, mocked_excludes, mocked_includes):
     # Inclusion list "wins"
     mocked_includes.return_value = ('explorer_',)
     mocked_excludes.return_value = ('explorer_',)
     res = schema.schema_info(CONN)
     tables = [x[0] for x in res]
     self.assertIn('explorer_query', tables)
 def test_schema_info_returns_valid_data(self, mocked_excludes, mocked_includes):
     mocked_includes.return_value = None
     mocked_excludes.return_value = []
     res = schema.schema_info(CONN)
     assert mocked_includes.called  # sanity check: ensure patch worked
     tables = [x[0] for x in res]
     self.assertIn('explorer_query', tables)
 def test_schema_info_returns_valid_data(self, mocked_excludes,
                                         mocked_includes):
     mocked_includes.return_value = None
     mocked_excludes.return_value = []
     res = schema.schema_info(CONN)
     tables = [x[0] for x in res]
     self.assertIn('explorer_query', tables)
 def test_app_inclusion_list(self, mocked_excludes, mocked_includes):
     mocked_includes.return_value = ('auth_', )
     mocked_excludes.return_value = []
     res = schema.schema_info(CONN)
     tables = [x[0] for x in res]
     self.assertNotIn('explorer_query', tables)
     self.assertIn('auth_user', tables)
 def test_app_inclusion_list_excluded(self):
     # Inclusion list "wins"
     schema._get_includes = lambda: ('explorer_',)
     schema._get_excludes = lambda: ('explorer_',)
     res = schema.schema_info(get_connection())
     tables = [x[0] for x in res]
     self.assertIn('explorer_query', tables)
 def test_app_inclusion_list(self, ):
     schema._get_includes = lambda: ('auth_',)
     schema._get_excludes = lambda: []
     res = schema.schema_info(get_connection())
     tables = [x[0] for x in res]
     self.assertNotIn('explorer_query', tables)
     self.assertIn('auth_user', tables)
 def test_app_inclusion_list(self, ):
     schema._get_includes = lambda: ('auth_', )
     schema._get_excludes = lambda: []
     res = schema.schema_info(get_connection())
     tables = [x[0] for x in res]
     self.assertNotIn('explorer_query', tables)
     self.assertIn('auth_user', tables)
 def test_app_inclusion_list(self, mocked_excludes, mocked_includes):
     mocked_includes.return_value = ('auth_', )
     mocked_excludes.return_value = []
     res = schema.schema_info(EXPLORER_CONNECTIONS['Postgres'])
     tables = [x.name.name for x in res]
     self.assertNotIn('explorer_query', tables)
     self.assertIn('auth_user', tables)
 def test_app_inclusion_list_excluded(self, mocked_excludes,
                                      mocked_includes):
     # Inclusion list "wins"
     mocked_includes.return_value = ('explorer_', )
     mocked_excludes.return_value = ('explorer_', )
     res = schema.schema_info(EXPLORER_CONNECTIONS['Postgres'])
     tables = [x.name.name for x in res]
     self.assertIn('explorer_query', tables)
 def test_schema_info_returns_valid_data(self, mocked_excludes,
                                         mocked_includes):
     mocked_includes.return_value = None
     mocked_excludes.return_value = []
     res = schema.schema_info(EXPLORER_CONNECTIONS['Postgres'])
     assert mocked_includes.called  # sanity check: ensure patch worked
     tables = [x.name.name for x in res]
     self.assertIn('explorer_query', tables)
     schemas = [x.name.schema for x in res]
     self.assertIn('public', schemas)
 def test_table_exclusion_list(self):
     schema._get_includes = lambda: None
     schema._get_excludes = lambda: ('explorer_', )
     res = schema.schema_info(get_connection())
     tables = [x[0] for x in res]
     self.assertNotIn('explorer_query', tables)
 def test_schema_info_returns_valid_data(self):
     schema._get_includes = lambda: None
     schema._get_excludes = lambda: []
     res = schema.schema_info(get_connection())
     tables = [x[0] for x in res]
     self.assertIn('explorer_query', tables)
 def test_builds_async(self, mocked_async_check):
     mocked_async_check.return_value = True
     self.assertIsNone(schema.schema_info(CONN))
     res = schema.schema_info(CONN)
     tables = [x[0] for x in res]
     self.assertIn('explorer_query', tables)
Example #22
0
File: views.py Project: grouwner/sc
 def get(self, request, *args, **kwargs):
     return render_to_response('explorer/schema.html',
                               {'schema': schema_info(get_connection())})
 def test_table_exclusion_list(self, mocked_excludes, mocked_includes):
     mocked_includes.return_value = None
     mocked_excludes.return_value = ('explorer_', )
     res = schema.schema_info(CONN)
     tables = [x[0] for x in res]
     self.assertNotIn('explorer_query', tables)
 def test_table_exclusion_list(self, mocked_excludes, mocked_includes):
     mocked_includes.return_value = None
     mocked_excludes.return_value = ('explorer_',)
     res = schema.schema_info(CONN)
     tables = [x[0] for x in res]
     self.assertNotIn('explorer_query', tables)
 def test_app_exclude_views(self, mocked_include_views):
     database_view = setup_sample_database_view()
     mocked_include_views.return_value = False
     res = schema.schema_info(CONN)
     tables = [x[0] for x in res]
     self.assertNotIn(database_view, tables)
 def test_builds_async(self, mocked_async_check):
     mocked_async_check.return_value = True
     self.assertIsNone(schema.schema_info(CONN))
     res = schema.schema_info(CONN)
     tables = [x[0] for x in res]
     self.assertIn('explorer_query', tables)
 def test_app_exclude_views(self, mocked_include_views):
     database_view = setup_sample_database_view()
     mocked_include_views.return_value = False
     res = schema.schema_info(CONN)
     tables = [x[0] for x in res]
     self.assertNotIn(database_view, tables)
Example #28
0
 def get(self, request, *args, **kwargs):
     return render_to_response('explorer/schema.html',
                               {'schema': schema_info(get_connection())})
 def test_builds_async(self, mocked_async_check):
     mocked_async_check.return_value = True
     self.assertIsNone(schema.schema_info(EXPLORER_CONNECTIONS['Postgres']))
 def test_table_exclusion_list(self):
     schema._get_includes = lambda: None
     schema._get_excludes = lambda: ('explorer_',)
     res = schema.schema_info(get_connection())
     tables = [x[0] for x in res]
     self.assertNotIn('explorer_query', tables)
Example #31
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     connection = self.kwargs['connection']
     context['tables'] = schema_info(connection)
     context['connection'] = connection
     return context
Example #32
0
 def test_table_exclusion_list(self, mocked_excludes, mocked_includes):
     mocked_includes.return_value = None
     mocked_excludes.return_value = ('data_explorer_explorer_', )
     res = schema.schema_info(EXPLORER_CONNECTIONS['Postgres'])
     tables = [x.name.name for x in res]
     self.assertNotIn('data_explorer_explorer_query', tables)
 def test_schema_info_returns_valid_data(self):
     schema._get_includes = lambda: None
     schema._get_excludes = lambda: []
     res = schema.schema_info(get_connection())
     tables = [x[0] for x in res]
     self.assertIn('explorer_query', tables)