Add CSV export support to partner catalog list endpoints via DRF rend…#51
Merged
Add CSV export support to partner catalog list endpoints via DRF rend…#51
Conversation
75fedf4 to
c0c747d
Compare
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CSV Export via DRF Content Negotiation (
?format=csv)Summary
?format=csvor sendingAccept: text/csvheaderEndpoints affected
GET /partner_catalog/api/v1/manage/catalogs/?format=csvcatalogs_report.csvGET /partner_catalog/api/v1/manage/catalogs/{pk}/learners/?format=csvlearners_report.csvGET /partner_catalog/api/v1/manage/catalogs/{pk}/courses/?format=csvcourses_report.csvGET /partner_catalog/api/v1/manage/catalogs/{pk}/enrollments/?format=csvenrollments_report.csvGET /partner_catalog/api/v1/manage/catalogs/{pk}/courses/{course_id}/enrollments/?format=csvcourse_enrollments_report.csvWhat changed
New files
partner_catalog/helpers/renderers.py— CustomCSVReportRenderer(DRFBaseRenderer) that flattens nested serializer data using dot notation and writes CSV with human-readable headers.partner_catalog/helpers/mixins.py—CSVExportMixinthat appends the CSV renderer, disables pagination for CSV responses, sets theContent-Dispositionheader, and works around Open edX'sURL_FORMAT_OVERRIDE = Nonesetting.Modified files
partner_catalog/api/v1/views.py— AddedCSVExportMixintoPartnerCatalogViewSet,CatalogLearnerViewset,CatalogCourseViewSet,CatalogEnrollmentsViewSet, andCatalogCourseEnrollmentViewSetwith per-viewsetcsv_fields,csv_labels, andcsv_filename.Test plan
GET .../catalogs/?format=csvreturns CSV with headers: Catalog Name, Slug, Status, Courses, Enrollments, Total Learners, Active Learners, Certified, Completion Rate, Available Start Date, Available End DateGET .../learners/?format=csvreturns CSV with headers: Full Name, Email, Active, Invite Sent At, Accepted At, Last Login, Enrollments, Certified, Removed AtGET .../courses/?format=csvreturns CSV with headers: Course Name, Position, Start Date, End Date, Enrollment Start, Enrollment End, Enrollments, Certified, Completion RateGET .../enrollments/?format=csvreturns CSV with headers: Full Name, Email, Active, Last Login, Course Name, Course ID, Progress, Has CertificateGET .../courses/{course_id}/enrollments/?format=csvreturns CSV with headers: Full Name, Email, Active, Last Login, Progress, Has CertificateAccept: text/csvheader also triggers CSV download?format=csv(e.g.?format=csv&search=john)?format=csv, endpoints return JSON as beforeContent-Disposition: attachment; filename="<name>.csv"header