Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable Wagtail API #3399

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

asajjad2
Copy link
Contributor

@asajjad2 asajjad2 commented Feb 11, 2025

What are the relevant tickets?

#6690

Description (What does it do?)

The PR adds the basic setup for testing the wagtail API

Changes:

  • Added basic setup for testing the Wagtail API.
  • Configured settings based on the official documentation: Wagtail API v2 Configuration.
  • Added a URL route at /api/v2/ to serve the Wagtail API.
  • Created a Wagtail API router utilizing built-in Page, Image, and Document viewsets under the cms application in wagtail_api.py.
  • Created a custom BackendFilter to filter a product by its readable_id
  • Created a custom serializer to return child_pages along with the parent
  • Extended the PagesAPIViewSet to expose useful Page meta fields

How can this be tested?

How to Test

  1. Clone and switch to the feature branch: areeb/6699-exploring-wagtail-api.

  2. Ensure xPRO is Properly Configured

  3. Generate an Access Token

    • Log in to the Django admin panel as an admin user.
    • Navigate to the access_tokens and generate a token against a user
  4. Set Up Postman for Testing

    • Open Postman and fork this collection.
    • Add the following environment variables to your postman enviornment:
      • base_url: Default if testing locally → http://xpro.odl.local:8053
      • access_token: The token generated in the previous step.
  5. Use Postman to make authenticated requests and explore the various Wagtail API endpoints.

@asajjad2 asajjad2 self-assigned this Feb 11, 2025
@arslanashraf7 arslanashraf7 changed the title feat: initial wagtail api testing feat: Enable Wagtail API Feb 11, 2025
Copy link
Contributor

@asadali145 asadali145 left a comment

Choose a reason for hiding this comment

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

I have added a few suggestions.

Comment on lines +44 to +47
api_router = WagtailAPIRouter("wagtailapi")
api_router.register_endpoint("pages", CustomPagesAPIViewSet)
api_router.register_endpoint("images", CustomImagesAPIViewSet)
api_router.register_endpoint("documents", CustomDocumentsAPIViewSet)
Copy link
Contributor

Choose a reason for hiding this comment

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

We do this in the urls.py.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add module, class, and method docs at all places.

Comment on lines +45 to +47
api_router.register_endpoint("pages", CustomPagesAPIViewSet)
api_router.register_endpoint("images", CustomImagesAPIViewSet)
api_router.register_endpoint("documents", CustomDocumentsAPIViewSet)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about we add a URL above the pages that would look like: api/v2/courses/<READABLE_ID>, Then our custom viewset can handle the readable ID and filter the data for us?
Same goes for the programs, api/v2/programs/<readable_id>

def filter_queryset(self, request, queryset, view):
field_name = "readable_id"
if field_name in request.GET:
value = request.GET[field_name].replace(" ", "+")
Copy link
Contributor

Choose a reason for hiding this comment

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

Any specific cases that we are trying to handle here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

readable_id is usually of this form course-v1:edX+DemoX+Demo_Course, when received as query params, it is converted to course-v1:edX DemoX Demo_Course, filtering on which would return nothing

Comment on lines +1148 to +1151
api_fields = [
APIField("child_pages", serializer=ProductChildPageSerializer()),
]

Copy link
Contributor

Choose a reason for hiding this comment

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

Current API does not return the custom page fields like: subhead etc. We should return the custom page data + child page fields as well.

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

Successfully merging this pull request may close these issues.

4 participants