Skip to content

Add CSV export support to partner catalog list endpoints via DRF rend…#51

Merged
Alec4r merged 2 commits intomain.v2from
crls/csv-export-renderer
Feb 16, 2026
Merged

Add CSV export support to partner catalog list endpoints via DRF rend…#51
Alec4r merged 2 commits intomain.v2from
crls/csv-export-renderer

Conversation

@ccantillo
Copy link

CSV Export via DRF Content Negotiation (?format=csv)

Summary

  • Add CSV export capability to partner catalog list endpoints using DRF's content negotiation
  • Clients request CSV by appending ?format=csv or sending Accept: text/csv header
  • No new endpoints, dependencies, or serializer changes required

Endpoints affected

Endpoint CSV filename
GET /partner_catalog/api/v1/manage/catalogs/?format=csv catalogs_report.csv
GET /partner_catalog/api/v1/manage/catalogs/{pk}/learners/?format=csv learners_report.csv
GET /partner_catalog/api/v1/manage/catalogs/{pk}/courses/?format=csv courses_report.csv
GET /partner_catalog/api/v1/manage/catalogs/{pk}/enrollments/?format=csv enrollments_report.csv
GET /partner_catalog/api/v1/manage/catalogs/{pk}/courses/{course_id}/enrollments/?format=csv course_enrollments_report.csv

What changed

New files

  • partner_catalog/helpers/renderers.py — Custom CSVReportRenderer (DRF BaseRenderer) that flattens nested serializer data using dot notation and writes CSV with human-readable headers.
  • partner_catalog/helpers/mixins.pyCSVExportMixin that appends the CSV renderer, disables pagination for CSV responses, sets the Content-Disposition header, and works around Open edX's URL_FORMAT_OVERRIDE = None setting.

Modified files

  • partner_catalog/api/v1/views.py — Added CSVExportMixin to PartnerCatalogViewSet, CatalogLearnerViewset, CatalogCourseViewSet, CatalogEnrollmentsViewSet, and CatalogCourseEnrollmentViewSet with per-viewset csv_fields, csv_labels, and csv_filename.

Test plan

  • GET .../catalogs/?format=csv returns CSV with headers: Catalog Name, Slug, Status, Courses, Enrollments, Total Learners, Active Learners, Certified, Completion Rate, Available Start Date, Available End Date
  • GET .../learners/?format=csv returns CSV with headers: Full Name, Email, Active, Invite Sent At, Accepted At, Last Login, Enrollments, Certified, Removed At
  • GET .../courses/?format=csv returns CSV with headers: Course Name, Position, Start Date, End Date, Enrollment Start, Enrollment End, Enrollments, Certified, Completion Rate
  • GET .../enrollments/?format=csv returns CSV with headers: Full Name, Email, Active, Last Login, Course Name, Course ID, Progress, Has Certificate
  • GET .../courses/{course_id}/enrollments/?format=csv returns CSV with headers: Full Name, Email, Active, Last Login, Progress, Has Certificate
  • Accept: text/csv header also triggers CSV download
  • Existing filters and search work with ?format=csv (e.g. ?format=csv&search=john)
  • Without ?format=csv, endpoints return JSON as before
  • Response includes Content-Disposition: attachment; filename="<name>.csv" header
  • Pagination is skipped for CSV (full dataset exported)

@ccantillo ccantillo requested a review from Alec4r February 12, 2026 21:52
@ccantillo ccantillo force-pushed the crls/csv-export-renderer branch from 75fedf4 to c0c747d Compare February 12, 2026 21:58
Copy link
Contributor

@Alec4r Alec4r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Alec4r Alec4r merged commit 3285881 into main.v2 Feb 16, 2026
4 checks passed
@Alec4r
Copy link
Contributor

Alec4r commented Feb 16, 2026

@dcoa @bra-i-am could you help me updating the MFE with the endpoints to download these CSVs? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments