Skip to content

Commit f6896c8

Browse files
committed
public api pagination fixes for table chart
1 parent 2254207 commit f6896c8

File tree

1 file changed

+52
-9
lines changed

1 file changed

+52
-9
lines changed

ddpui/api/public_api.py

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,9 @@ def validate_public_dashboard(request, token: str):
486486
"/dashboards/{token}/charts/{chart_id}/data-preview/",
487487
response={200: dict, 404: PublicErrorResponse},
488488
)
489-
def get_public_chart_data_preview(request, token: str, chart_id: int):
489+
def get_public_chart_data_preview(
490+
request, token: str, chart_id: int, page: int = 0, limit: int = 100
491+
):
490492
"""
491493
Get public chart data preview - ESSENTIAL for table charts
492494
@@ -507,12 +509,6 @@ def get_public_chart_data_preview(request, token: str, chart_id: int):
507509
# Verify dashboard is public
508510
dashboard = Dashboard.objects.get(public_share_token=token, is_public=True)
509511

510-
# Import required modules
511-
from ddpui.models.visualization import Chart
512-
from ddpui.models.org import OrgWarehouse
513-
from ddpui.core.charts import charts_service
514-
from ddpui.schemas.chart_schema import ChartDataPayload
515-
516512
# Get the chart and org warehouse
517513
chart = Chart.objects.filter(id=chart_id, org=dashboard.org).first()
518514
if not chart:
@@ -530,8 +526,10 @@ def get_public_chart_data_preview(request, token: str, chart_id: int):
530526
# Convert payload to ChartDataPayload
531527
chart_payload = ChartDataPayload(**payload)
532528

533-
# Get table preview using same function as authenticated API
534-
preview_data = charts_service.get_chart_data_table_preview(org_warehouse, chart_payload)
529+
# Get table preview using same function as authenticated API with pagination
530+
preview_data = charts_service.get_chart_data_table_preview(
531+
org_warehouse, chart_payload, page, limit
532+
)
535533

536534
return {
537535
"columns": preview_data["columns"],
@@ -966,3 +964,48 @@ def download_public_chart_data_csv(request, token: str, chart_id: int, payload:
966964
except Exception as e:
967965
logger.error(f"Public CSV download error for chart {chart_id}: {str(e)}")
968966
raise HttpError(500, f"CSV download failed: {str(e)}")
967+
968+
969+
@public_router.post(
970+
"/dashboards/{token}/charts/{chart_id}/data-preview/total-rows/",
971+
response={200: dict, 404: PublicErrorResponse},
972+
)
973+
def get_public_chart_data_preview_total_rows(request, token: str, chart_id: int):
974+
"""
975+
Get total row count for public chart data preview
976+
This is essential for proper pagination in table charts
977+
"""
978+
try:
979+
# Verify dashboard is public
980+
dashboard = Dashboard.objects.get(public_share_token=token, is_public=True)
981+
982+
# Get the chart and org warehouse
983+
chart = Chart.objects.filter(id=chart_id, org=dashboard.org).first()
984+
if not chart:
985+
raise Exception("Chart not found in dashboard's organization")
986+
987+
org_warehouse = OrgWarehouse.objects.filter(org=dashboard.org).first()
988+
if not org_warehouse:
989+
raise Exception("No warehouse configured for organization")
990+
991+
# Get payload from request body
992+
import json
993+
994+
payload = json.loads(request.body) if request.body else {}
995+
996+
# Convert payload to ChartDataPayload
997+
chart_payload = ChartDataPayload(**payload)
998+
999+
# Get total rows using same function as authenticated API
1000+
total_rows = charts_service.get_chart_data_total_rows(org_warehouse, chart_payload)
1001+
1002+
return {"total_rows": total_rows, "is_valid": True}
1003+
1004+
except Dashboard.DoesNotExist:
1005+
logger.warning(f"Public total rows access failed - dashboard not found for token: {token}")
1006+
return 404, PublicErrorResponse(
1007+
error="Dashboard not found or no longer public", is_valid=False
1008+
)
1009+
except Exception as e:
1010+
logger.error(f"Public total rows error for chart {chart_id}: {str(e)}")
1011+
return 404, PublicErrorResponse(error="Total rows unavailable", is_valid=False)

0 commit comments

Comments
 (0)