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

Add API endpoint for pattern rendering via POST #168

Merged
merged 4 commits into from
Jan 25, 2022

Conversation

thibaudcolas
Copy link
Member

@thibaudcolas thibaudcolas commented Dec 22, 2021

Description

Addresses #104. This adds an API endpoint built into the pattern library, and changes how tag overrides are loaded. This is so they can be loaded from the API data, rather than always loading the YAML file.

I could use additional feedback on this before adding the tests.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have added an appropriate CHANGELOG entry

To test this:

 echo '{"template_name": "patterns/molecules/button/button.html", "config": {"context": {"target_page": {"title": "API"}}, "tags": {"pageurl":{"target_page":{"raw": "/hello-api"}}}}}' | curl -d @- http://localhost:8000/pattern-library/api/v1/render-pattern

Suggested CHANGELOG entry:

### Added

- New `/api/v1/render-pattern` [API endpoint to render patterns](https://torchbox.github.io/django-pattern-library/recipes/api-rendering/) via POST requests, with the pattern’s context and tag overrides as a JSON body ([#168](https://github.com/torchbox/django-pattern-library/pull/168)).

@thibaudcolas thibaudcolas added enhancement New feature or request django Related to Django templates capabilities status: Needs work labels Dec 22, 2021
@thibaudcolas thibaudcolas added this to the Nice to have milestone Dec 22, 2021
@thibaudcolas thibaudcolas modified the milestones: Nice to have, v1.0.0 Jan 19, 2022
@thibaudcolas thibaudcolas marked this pull request as ready for review January 24, 2022 09:33
Copy link
Collaborator

@bcdickinson bcdickinson left a comment

Choose a reason for hiding this comment

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

I think there's some subtle things that need changing in render_pattern(), and it would also be good to see some tests that call the API and check this is functioning as intended, but this look 95% good to me.

pattern_library/monkey_utils.py Outdated Show resolved Hide resolved
pattern_library/monkey_utils.py Outdated Show resolved Hide resolved
pattern_library/utils.py Outdated Show resolved Hide resolved
pattern_library/views.py Show resolved Hide resolved
@thibaudcolas thibaudcolas force-pushed the feature/104-api-rendering branch 2 times, most recently from d92dfee to 513898d Compare January 25, 2022 14:46
@thibaudcolas
Copy link
Member Author

Code changes from feedback: check. Tests: check. Docs: check! Re-running black and isort three times: check.

@thibaudcolas thibaudcolas merged commit 983ac1c into main Jan 25, 2022
@thibaudcolas thibaudcolas deleted the feature/104-api-rendering branch January 25, 2022 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
django Related to Django templates capabilities enhancement New feature or request
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Add support for rendering patterns over an API endpoint
2 participants