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 REST API functionality for generating menus #302

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

Conversation

ababic
Copy link
Collaborator

@ababic ababic commented Dec 2, 2018

Resolves #278.

To do list:

  • Implement the API views as GET endpoints
  • Implement custom forms and fields for validating GET arguments and supplying useful feedback
  • Implement a custom Renderer class to allow view arguments to be updated easily in the Browsable API
  • Implement custom Serializer classes to support recursive rendering of menu items
  • Implement a way to easily customise serializers for flat/main menu items
  • Implement a way to separately customise serialization of sub-menu items in flat/main menus
  • Implement a way to easily customise serializers for items in children and section menus
  • Add a setting to allow the renderer settings to be controlled
  • Add unit tests
  • Add documentation

There are endpoints for generating the following menu types:

  • main menus
  • flat menus
  • children menus
  • section menus

Each endpoint acts in a similar way to the equivalent template tag, only rendering the menu as JSON instead of to a template. If you're familiar with the tags, you should recognise the options that are available in the API. You just have to provide a few more values, as there's no existing request context to pull existing values from.

The best way to see how they all work is to check out each one in the Browsable API view, where an 'Arguments' form will explain all of the arguments accepted for each view.

Anyone wanting to give this a whirl for themselves should be able to do so by following these instructions:

  1. Install the PR version from github using:
    pip install git+https://github.com/ababic/wagtailmenus.git@menus_api
    
  2. Add 'wagtailmenus.api' to INSTALLED_APPS in your project's settings
  3. If it's not already there, add 'rest_framework' to INSTALLED_APPS in your project's settings
  4. Update urls.py for your project to include the wagtailmenus.api.urls, e.g:
    urlpatterns = [
        ...
        url(r'^wagtailmenus_api/', include('wagtailmenus.api.urls')),  # This is new!
        url(r'', include(wagtail_urls)),
    ]
    
  5. Load up the v1 index URL in your browser with ?format=api on the end to get the Browsable API view, e.g: http://127.0.0.1:8000/wagtailmenus_api/v1/?format=api

Or, if you want to try things out without interfering with an existing project, you can clone my branch and follow these instructions to get a version up and running:

https://wagtailmenus.readthedocs.io/en/latest/contributing/index.html#developing-locally

@codecov
Copy link

codecov bot commented Dec 2, 2018

Codecov Report

Merging #302 into master will decrease coverage by 4.81%.
The diff coverage is 73.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #302      +/-   ##
==========================================
- Coverage   98.26%   93.44%   -4.82%     
==========================================
  Files          89       94       +5     
  Lines        2945     3465     +520     
==========================================
+ Hits         2894     3238     +344     
- Misses         51      227     +176     
Impacted Files Coverage Δ
wagtailmenus/settings/base.py 100.00% <ø> (ø)
wagtailmenus/tests/urls.py 100.00% <ø> (ø)
wagtailmenus/utils/misc.py 56.52% <24.00%> (-37.85%) ⬇️
wagtailmenus/api/v1/renderers.py 50.00% <50.00%> (ø)
wagtailmenus/api/v1/serializers.py 56.31% <56.31%> (ø)
wagtailmenus/api/v1/views.py 57.65% <57.65%> (ø)
wagtailmenus/api/v1/forms.py 66.03% <66.03%> (ø)
wagtailmenus/api/v1/form_fields.py 83.92% <83.92%> (ø)
wagtailmenus/api/v1/tests/mixins.py 94.54% <94.54%> (ø)
wagtailmenus/api/conf/defaults.py 100.00% <100.00%> (ø)
... and 49 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b1f13b0...f82305b. Read the comment docs.

@ababic ababic mentioned this pull request Dec 2, 2018
@ababic ababic force-pushed the menus_api branch 4 times, most recently from c0ba2ee to cade063 Compare June 19, 2019 21:47
@ababic ababic force-pushed the menus_api branch 13 times, most recently from d3f6977 to f2c4ffb Compare July 9, 2019 10:28
@ababic ababic force-pushed the menus_api branch 11 times, most recently from 1eeb2b6 to 560a91f Compare July 30, 2019 09:41
…dation

- Added '_id' to the end of all page fields to reinforce that an ID value should be supplied
- Make apply_active_classes False by default
- Make ChildrenMenuGeneratorArgumentForm.parent_page required
…ation (for menus, menu items and menu item page data)
…gs() and remove 'base_class' as the first parameter
…ITE_MODE to simplify things for single-site projects
…ribute names

- Use ImproperlyConfigured errors instead of NotImplementedError in views
…sion_classes and renderer_classes for menu generator views
- Replace custom form fields with serialiser fields
- Move default option value handling to option serializers from views
- Make option serializers swappable via settings
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.

Menus API
1 participant