Skip to content

Commit

Permalink
Modify /type_suggestions/ path response to include inferred display…
Browse files Browse the repository at this point in the history
… type options
  • Loading branch information
silentninja committed Mar 18, 2022
1 parent 14efb5f commit 07f24db
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion mathesar/api/db/viewsets/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
from db.types.exceptions import UnsupportedTypeException
from mathesar.api.dj_filters import TableFilter
from mathesar.api.pagination import DefaultLimitOffsetPagination
from mathesar.api.serializers.columns import SimpleColumnSerializer
from mathesar.api.serializers.tables import TableSerializer, TablePreviewSerializer
from mathesar.models import Table
from mathesar.utils.display_options_inference import get_table_column_display_options
from mathesar.utils.tables import (
get_table_column_types
)
Expand Down Expand Up @@ -67,8 +69,19 @@ def destroy(self, request, pk=None):
@action(methods=['get'], detail=True)
def type_suggestions(self, request, pk=None):
table = self.get_object()
inferred_column_data = []
col_types = get_table_column_types(table)
return Response(col_types)
display_options = get_table_column_display_options(table, col_types)
for col_name, col_type in col_types.items():
column_data = {
'name': col_name,
'type': col_type,
'display_options': display_options.get(col_name, None)
}
inferred_column_data.append(column_data)
serializer = SimpleColumnSerializer(data=inferred_column_data, many=True)
if serializer.is_valid(raise_exception=True):
return Response(serializer.data)

@action(methods=['post'], detail=True)
def previews(self, request, pk=None):
Expand Down

0 comments on commit 07f24db

Please sign in to comment.