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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
23cb96d
Add API functionality that can be used to generate JSON representatio…
Dec 2, 2018
27ad67e
Tweak validation errors
Dec 2, 2018
1caee75
Add a make_dummy_request() method to help with derive pages from 'cur…
Dec 2, 2018
9a1a835
Add 'djangorestframework-recursive' dependency to setup.py
Dec 2, 2018
4008eab
Add a 'base' urls file that will be update to include new versions as…
Dec 2, 2018
c68054d
Add menu_api urls to test.urls
Dec 2, 2018
2b76763
Rewording of help text for 'current_url'
Dec 2, 2018
08e1e73
Add a custom field for 'handle' in FlatMenuGeneratorArgumentForm that…
Dec 2, 2018
24905bf
Use get_initial_for_field() here so that initial values in field defi…
Dec 3, 2018
9776a9a
Multilingual support: Add 'language' field to form, and activate the …
Dec 3, 2018
35f50fe
Only supplement values from initial data if the field is not required…
Dec 3, 2018
a3c4749
Minor docstring tweaks
Dec 3, 2018
ee370f8
Add namespacing for URLs
Dec 3, 2018
d93143e
Move missing data supplementation logic out to a separate method to m…
Dec 3, 2018
ef382a2
Simplify BaseAPIViewArgumentForm.to_html() - Can't see a good reason …
Dec 3, 2018
9aa8bb9
Update conditional logic for BaseAPIViewArgumentForm.helper() to make…
Dec 3, 2018
2451a6d
Rename template() to template_name()
Dec 3, 2018
5c6cd35
Start adding tests (focusing on forms first)
Dec 3, 2018
34d94d6
Update ArgumentFormTestMixin.make_request() to be a bit more flexible
Dec 3, 2018
20d596c
- Rename get_dummy_request() to make_dummy_request(), and update it t…
Dec 3, 2018
e634d7b
Fix typo on field name
Dec 3, 2018
a3bb1fc
Rename guess_page_from_url() to get_page_for_url()
Dec 3, 2018
29d5fbb
Don't ever add an error because of failure to derive a page. If it ca…
Dec 3, 2018
627e2f2
Rename 'test_forms' module to 'test_base_forms' and add bunch of test…
Dec 3, 2018
7513248
Remove setting of attribute that is no longer used
Dec 3, 2018
d75f600
Use a better pattern for overriding derive_current_page() - the curre…
Dec 4, 2018
2a95141
Remove TestBaseMenuGeneratorArgumentFormCommonMethods from here - run…
Dec 4, 2018
af1924d
Use JSONRenderer by default (format=api must be added to the URL to a…
Dec 4, 2018
4b12e37
Minor comment additions
Dec 4, 2018
963caa2
Update ArgumentFormTestMixin.get_form() to support a 'set_errors' arg…
Dec 4, 2018
b5b0928
Minor formatting amend
Dec 4, 2018
74f6411
Add tests for ChildrenMenuGeneratorArgumentForm.derive_parent_page() …
Dec 4, 2018
c727b58
Be consistent in using assertNumQueries() to help show how the method…
Dec 4, 2018
46cc53e
Import wagtailmenus core settings as wagtailmenus_settings for clarity
Dec 5, 2018
63bbd27
Serializer/setting revision
Dec 5, 2018
ce7a9f6
View updates
Dec 5, 2018
00ce96b
Fix a couple of method name errors in MenuGeneratorView.get_serializer()
Dec 10, 2018
dff0ee1
Make site not required, and if not supplied, attempt to derive the va…
Dec 10, 2018
71739dc
The find_for_request() method is on the Site model, not the manager
Dec 10, 2018
2bf8b8c
Factor out site identification from derive_site() to a new get_site_f…
Dec 10, 2018
ce55f6e
Add tests for derive_site()
Dec 10, 2018
20c33dd
Add tests for get_site_for_request()
Dec 10, 2018
f023673
Reorder BaseMenuGeneratorArgumentForm methods and update get_page_for…
Dec 10, 2018
cda2d54
Add tests for get_page_for_url
Dec 10, 2018
68cbaf2
Add basic tests to show views are not 500ing
Dec 10, 2018
ce4b4b6
Move site and page fetching logic to utils.misc and update tests acco…
Dec 10, 2018
090a571
Update context processor to use updated functions from utils.misc
Dec 10, 2018
d9d5e4c
Fix eronous patch on test
Dec 10, 2018
339df47
Add a test for MenuGeneratorIndexView too
Dec 10, 2018
4cd3316
Shorten NotImplementedError messages
Dec 10, 2018
59e3dd3
Remove the now redundant get_page_for_url() method from BaseMenuGener…
Dec 11, 2018
fecc73f
Move make_dummy_request() to bottom of BaseMenuGeneratorArgumentForm …
Dec 11, 2018
817a21d
Move language activation logic to MenuGeneratorView.get(), and also a…
Dec 11, 2018
45f2166
Don't add full stops to error messages
Dec 11, 2018
6e6461e
Update make_dummy_request() in-line with wagtail change in https://gi…
Dec 11, 2018
e846f02
Add full stops to ALL validation error messages, so it is at least co…
Dec 11, 2018
1d46f93
Reorder methods on MenuGeneratorView
Dec 11, 2018
ca26dde
Add a few more view tests
Dec 11, 2018
d17a2c7
Update Menu._create_contextualvals_obj_from_context() to respect 'cur…
Dec 11, 2018
83298f9
Values in error messages seem not to be getting substituted, so keep …
Dec 11, 2018
b999c37
Tweak error text again
Dec 11, 2018
fd18c38
Split view tests into two separate modules and add tests for 'get_ser…
Dec 11, 2018
9e9860b
Add .coveragerc to help make coverage reports more useful
Dec 14, 2018
0fcc0f3
Add test to show handling of Site.DoesNotExist in get_site_from_reque…
Dec 14, 2018
2642a96
Added test that uses format=api to activate the custom renderer, whic…
Dec 14, 2018
7d6c620
Tweak source value in .coveragerc
Dec 14, 2018
604d6fe
Remove pointless query here (we're mocking the method)
Dec 14, 2018
8d43cdb
Shorten api setting names by removing 'DEFAULT_'
Dec 15, 2018
61068d1
Remove unnecessary try/except from _clean_triggers_call_to_method()
Dec 15, 2018
e943634
Replace InstanceSpecificFieldsMixin with ContextSpecificFieldsMixin m…
Dec 16, 2018
158f758
Add 'api_fields' and 'api_page_fields' attributes to AbstractMenuItem…
Dec 23, 2018
a8ec3db
Add 'api_fields' attributes to AbstractMainMenu and AbstractFlatMenu …
Dec 23, 2018
ab92fc4
Rename api field attribute names on AbstractMenuItem and add attribut…
Dec 23, 2018
4c99743
Remove child_api_fields and and child_api_page fields from AbstractMe…
Dec 24, 2018
3961450
Add field lists to ChildrenMenu and SectionMenu too, to allow custom …
Dec 24, 2018
df802bd
Move the api settings module into the v1 sub app. this way, new versi…
Dec 31, 2018
2f38703
Update renderer classes for MenuGeneratorIndexView to render to JSON …
Dec 31, 2018
82186dd
Use 'serializer' instead of 'field' in method names where the functio…
Dec 31, 2018
d430477
Add settings to allow menu item serializer fields to be overridden fo…
Dec 31, 2018
cf94725
Split serializers module into it's own sub-app and update menu serial…
Dec 31, 2018
cdfe275
Add methods to ChildrenMenuSerializer and SectionMenuSerializer for g…
Dec 31, 2018
33af7ef
Add some settings to allow page representation to controlled for each…
Dec 31, 2018
62127af
Update menu classes with a get_item_page_serializer_fields() method t…
Dec 31, 2018
2219d52
Update MenuItemSerializerMixin.get_page_serializer_class() to use the…
Dec 31, 2018
e7db700
Use two base classes to create DefaultSectionRootSerializer, so that …
Dec 31, 2018
958a87b
Use None values for settings so that values are picked up from menu/m…
Dec 31, 2018
d4c7187
Add a few more tests for menu specific views
Dec 31, 2018
90c201b
Use non-plurals in new module names
Dec 31, 2018
e1a6b11
Drop the 'Default' from the beginning of dynamically generated class …
Dec 31, 2018
56d82d9
Simplify views by removing the 'default_serializer_class' attribute a…
Dec 31, 2018
ff3155c
Shorten field setting names
Dec 31, 2018
404b0ac
Use the translation.override context manager to temporarily activate …
ababic Jun 17, 2019
c14c40e
View class simplification
ababic Jun 18, 2019
df0e665
Simplify serializers and settings
ababic Jun 19, 2019
8e1e60a
backtrack on classmethod use for forms
ababic Jun 19, 2019
045e20b
Fix ArgumentFormTestMixin.get_form()
ababic Jun 19, 2019
36b250b
Remove request argument from get_form_initial()
ababic Jun 19, 2019
ee8ebc0
Fix get_form_init_kwargs()
ababic Jun 19, 2019
72ec961
Fix base class reference
ababic Jun 19, 2019
87d9490
More fixes
ababic Jun 19, 2019
7700264
Simplify serializers by utilising SerializerMethodField
ababic Jun 20, 2019
dc76dd0
Remove ContextSpecificFieldsMixin and fix a lot of breakages
ababic Jun 24, 2019
cf3eff3
Make serializer class fetching from settings lazy
ababic Jul 2, 2019
521b79a
Attempt to fix failing tests
ababic Jul 5, 2019
ea09fbd
Use appropriate values for AbstractMenuItem.sub_item_page_api_fields
ababic Jul 6, 2019
6d50d65
Serializer improvements
ababic Jul 6, 2019
e6d1ade
Use PageSerializer to render page details for menu items by default
ababic Jul 6, 2019
62363e2
Use a CharField for current_url to allow relative urls to be supplied
ababic Jul 6, 2019
c132426
Remove redundant RecursiveField import
ababic Jul 7, 2019
d751218
Further refactoring
ababic Jul 7, 2019
d92b289
Minor formatting/docstring amends for menu serializers
ababic Jul 7, 2019
259ec45
Fix some errors in forms
ababic Jul 8, 2019
b6a3629
Move derivation logic to views
ababic Jul 8, 2019
80adb89
Always attempt to derive the current site, and fix attribute name issue
ababic Jul 8, 2019
76032ee
Update form field help text
ababic Jul 9, 2019
68fd750
- Rename get_augmented_form_data() to process_form_data()
ababic Jul 9, 2019
38c5742
Remove unnecessary __init__ override from BaseAPIViewArgumentForm
ababic Jul 9, 2019
27382c9
Override label_from_instance for PageChoiceField
ababic Jul 9, 2019
8b277df
derive_page function replaces get_page_from_request
ababic Jul 24, 2019
d5f5a0f
No need to specify use_specific any longer
ababic Jul 24, 2019
8a98800
Remove / amend failing/irrelevant form tests
ababic Jul 24, 2019
b0ee62d
Remove old tests for get_page_from_request()
ababic Jul 24, 2019
6339c13
make_dummy_request() has moved to wagtailmenus.api.utils
ababic Jul 24, 2019
51ab47c
Move 'ancestor derivation' to it's own util function
ababic Jul 25, 2019
d55a03a
Form updates:
ababic Jul 25, 2019
7ac8c5c
View logic tweaks
ababic Jul 25, 2019
7eb00a3
- Move value derivation logic back to forms and tidy cross-field vali…
ababic Jul 28, 2019
2d3a593
Add make_serializer_class() function to aid in dynamic creation of se…
ababic Jul 28, 2019
2015ede
Adopt wagtail.api.APIField as a means of allowing serializer customis…
ababic Jul 28, 2019
060165f
Get current tests passing
ababic Jul 28, 2019
5f3f784
Use 'ancestor_page_ids' to set the relevant value in dummy_context
ababic Jul 28, 2019
ff0c65c
Rename use_relative_page_urls to relative_page_urls
ababic Jul 28, 2019
1b37c7f
Update tests to account for field name change
ababic Jul 28, 2019
2aa1ec9
Use field names as labels
ababic Jul 28, 2019
aa572e2
Finish up form field renaming
ababic Jul 28, 2019
8f0db58
Shuffle serializer field order
ababic Jul 28, 2019
c567a77
Update choice labels for JavascriptStyleBooleanSelect
ababic Jul 28, 2019
4f9950f
Rename MenuBasedMenuGeneratorView to BaseModelMenuGeneratorView
ababic Jul 28, 2019
441824e
Remove unused global from views
ababic Jul 28, 2019
b817af6
Base view tests
ababic Jul 28, 2019
22005cd
Remove BASE_MAIN_MENU_SERIALIZER and BASE_FLAT_MENU_SERIALIZER in fav…
ababic Jul 29, 2019
d9e4a96
Update tests
ababic Jul 29, 2019
2837a55
Rename x_serializer_init_kwargs() methods to x_serializer_create_kwar…
ababic Jul 29, 2019
919cc1c
Remove some unnecessary lines/variabalisation from _prime_menu_item()
ababic Jul 29, 2019
80500ea
Provide request with calleing relative_url() for root_page
ababic Jul 29, 2019
e4db54b
Improve override instructions for 'api_fields' attributes on menu and…
ababic Jul 29, 2019
0fd3641
Optimise PageChoiceField
ababic Jul 29, 2019
70b5619
Allow current_site_id to be provided (if available), and add SINGLE_S…
ababic Jul 30, 2019
203027c
Utilise the new request_forms block to output custom argument form
ababic Jul 30, 2019
7ca2013
- Refer to the argument form as 'argument_form' in view classes / att…
ababic Jul 30, 2019
f82305b
Utilise settings to allow control over authentication_classes, permis…
ababic Jul 30, 2019
e89ae9a
Begin refactoring argument forms as serializers. TODO:
ababic Sep 6, 2020
d17ad08
Rename get_menu_instance -> get_object
ababic Dec 28, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# .coveragerc to control coverage.py
[run]
branch = True

source = wagtailmenus/*

omit =
*/migrations/*


[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
def __repr__
if self\.debug

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
return NotImplemented

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:

ignore_errors = True

[html]
directory = coverage_html_report
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'beautifulsoup4<4.6.1,>=4.5.1',
'coverage>=4.5',
'django-webtest>=1.9,<1.10',
'django-crispy-forms>=1.7,<1.8',
]

development_extras = [
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ envlist =

[testenv]
install_command = pip install -e ".[testing]" -U {opts} {packages}
commands = coverage run --source=wagtailmenus runtests.py
commands = coverage run runtests.py

basepython =
py34: python3.4
Expand Down
Empty file added wagtailmenus/api/__init__.py
Empty file.
140 changes: 140 additions & 0 deletions wagtailmenus/api/form_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
from functools import lru_cache

from django import forms
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from wagtail.core.models import Page, Site

from wagtailmenus.conf import constants, settings


@lru_cache(maxsize=64)
def get_label_indent(depth, indent_string):
if depth > 1:
return ''.join(str(indent_string) for i in range(depth-2))
return ''


class IndentedPageChoiceIterator(forms.models.ModelChoiceIterator):
indent_string = ' - '

def __init__(self, field):
self.field = field
# Limit fields to help with performance
self.queryset = field.queryset.only('id', 'depth', 'title')

def label_from_instance(self, obj):
# Indent field labels according to depth (if enabled)
if self.field.indent_choice_labels:
return '{indent}{title}'.format(
indent=get_label_indent(obj.depth, self.indent_string),
title=obj.title,
)
return obj.title

def choice(self, obj):
# Use the above label_from_instance() method instead
# of the one
return (self.field.prepare_value(obj), self.label_from_instance(obj))


class JavascriptStyleBooleanSelect(forms.Select):

def __init__(self, attrs=None):
choices = (
('true', _('true')),
('false', _('false')),
)
super().__init__(attrs, choices)

def format_value(self, value):
try:
return {
True: 'true',
False: 'false',
'True': 'true',
'False': 'false',
'true': 'true',
'false': 'false',
1: 'true',
0: 'false',
'1': 'true',
'0': 'false',
}[value]
except KeyError:
return ''

def value_from_datadict(self, data, files, name):
value = data.get(name)
return {
True: True,
False: False,
'True': True,
'False': False,
'true': True,
'false': False,
'1': True,
'0': False,
}.get(value)


class BooleanChoiceField(forms.BooleanField):
widget = JavascriptStyleBooleanSelect

def clean(self, value):
if value is None:
raise ValidationError("The value must be 'true' or 'false'.", code="invalid")
return value


class MaxLevelsChoiceField(forms.TypedChoiceField):

default_error_messages = {
'invalid_choice': _('The provided value is not a supported.')
}

def __init__(self, *args, **kwargs):
empty_label = kwargs.pop('empty_label', '-----')
choices = (('', empty_label),) + constants.MAX_LEVELS_CHOICES
defaults = {
'choices': choices,
'coerce': int,
'empty_value': None,
}
kwargs.update({k: v for k, v in defaults.items() if k not in kwargs})
super().__init__(*args, **kwargs)


class PageIDChoiceField(forms.ModelChoiceField):

default_error_messages = {
'invalid_choice': _('The provided value is not a valid page ID.')
}

iterator = IndentedPageChoiceIterator

def __init__(self, *args, **kwargs):
if 'queryset' not in kwargs:
kwargs['queryset'] = Page.objects.filter(depth__gt=1)
self.indent_choice_labels = kwargs.pop('indent_choice_labels', True)
super().__init__(*args, **kwargs)


class SiteIDChoiceField(forms.ModelChoiceField):

default_error_messages = {
'invalid_choice': _('The provided valie is not a valid site ID.')
}

def __init__(self, *args, **kwargs):
if 'queryset' not in 'kwargs':
kwargs['queryset'] = Site.objects.all()
super().__init__(*args, **kwargs)


class FlatMenuHandleField(forms.SlugField):

def __init__(self, *args, **kwargs):
if settings.FLAT_MENUS_HANDLE_CHOICES:
kwargs['widget'] = forms.Select(choices=settings.FLAT_MENUS_HANDLE_CHOICES)
super().__init__(*args, **kwargs)
6 changes: 6 additions & 0 deletions wagtailmenus/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.conf.urls import include, url

app_name = 'wagtailmenus_api'
urlpatterns = [
url(r'^v1/', include('wagtailmenus.api.v1.urls', namespace='v1')),
]
127 changes: 127 additions & 0 deletions wagtailmenus/api/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
from io import StringIO
from urllib.parse import urlparse

from django.conf import settings
from django.core.handlers.base import BaseHandler
from django.core.handlers.wsgi import WSGIRequest
from wagtail.core.sites import get_site_for_hostname

from wagtailmenus.utils.misc import derive_page


def derive_current_site(request, site_page, url):
"""
Attempts to find a ``Site`` object for the current ``request``.
using the supplied ``site_page`` or ``url``.

This function makes some assumptions about how Wagtail is being
used, and might not be appropriate for all implementations.
If needed, you can implement an alternative derivation function
(accepting the same arguments as this one) and register it using the
``WAGTAILMENUS_API_V1_CURRENT_SITE_DERIVATION_FUNCTION`` setting.
"""
if site_page is not None:
return site_page.get_site()
parsed_url = urlparse(url)
port = parsed_url.port or 443 if parsed_url.scheme == 'https' else 80
return get_site_for_hostname(parsed_url.hostname, port)


def derive_current_page(request, site, url):
"""
Attempts to find a ``Page`` object matching the supplied ``url`` for the
current API ``request``. Returns a tuple with two items, where the first
is the matching ``Page`` (or ``None`` if no match was found), and the
second a boolean indicating whether the match was an exact match for
the URL (or ``False`` if no match was found).

This function uses Wagtail's built-in page routing mechanism to find
a matching page. In order to do this, a 'dummy request' is created from
``api_request`` for the supplied ``url``. This approach might not be
appropriate for all implementations. If needed, you can implement an
alternative derivation function (accepting the same arguments as this one)
and register it using the ``WAGTAILMENUS_API_V1_CURRENT_PAGE_DERIVATION_FUNCTION``
setting.
"""

# Create a dummy request is created for the supplied URL, but otherwise
# matching
dummy_request = make_dummy_request(url, request)
return derive_page(dummy_request, site)


def make_dummy_request(url, original_request, **metadata):
"""
Construct a HttpRequest object that is, as far as possible,
representative of the original request - only for the provided ``url``
instead of the one that was originally requested.
"""
url_info = urlparse(url)
hostname = url_info.hostname
path = url_info.path
port = url_info.port or (443 if url_info.scheme == 'https' else 80)
scheme = url_info.scheme

dummy_values = {
'REQUEST_METHOD': 'GET',
'PATH_INFO': path,
'SERVER_NAME': hostname,
'SERVER_PORT': port,
'SERVER_PROTOCOL': 'HTTP/1.1',
'HTTP_HOST': hostname,
'wsgi.version': (1, 0),
'wsgi.input': StringIO(),
'wsgi.errors': StringIO(),
'wsgi.url_scheme': scheme,
'wsgi.multithread': True,
'wsgi.multiprocess': True,
'wsgi.run_once': False,
}

# Add important values from the original request object
headers_to_copy = [
'REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR', 'HTTP_COOKIE',
'HTTP_USER_AGENT', 'HTTP_AUTHORIZATION', 'wsgi.version',
'wsgi.multithread', 'wsgi.multiprocess', 'wsgi.run_once',
]
if settings.SECURE_PROXY_SSL_HEADER:
headers_to_copy.append(settings.SECURE_PROXY_SSL_HEADER[0])
for header in headers_to_copy:
if header in original_request.META:
dummy_values[header] = original_request.META[header]

# Add additional custom metadata sent by the caller.
dummy_values.update(**metadata)

request = WSGIRequest(dummy_values)

# Add a flag to let middleware know that this is a dummy request.
request.is_dummy = True

# Apply middleware to the request
handler = BaseHandler()
handler.load_middleware()
handler._middleware_chain(request)

return request


def make_serializer_class(name, base_class, field_names, model=None, field_serializer_overrides=None, **additional_attributes):
_model = model

if _model is not None:
class Meta:
model = _model
fields = list(field_names)
else:
class Meta:
fields = list(field_names)

attrs = {'Meta': Meta}

if field_serializer_overrides:
attrs.update(field_serializer_overrides)

attrs.update(additional_attributes)

return type(name, (base_class, ), attrs)
Empty file added wagtailmenus/api/v1/__init__.py
Empty file.
Empty file.
52 changes: 52 additions & 0 deletions wagtailmenus/api/v1/conf/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# NOTE: All supported app settings must be added here

# --------------------
# REST Framework views
# --------------------

# Use the REST framework defaults by default
AUTHENTICATION_CLASSES = None

# Use the REST framework defaults by default
PERMISSION_CLASSES = None

# Use custom renderer by default. Override this setting to hide the browsable
# API in production
RENDERER_CLASSES = [
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
]

# -------------------------
# Option serializer classes
# -------------------------

CHILDREN_MENU_OPTION_SERIALIZER = 'wagtailmenus.api.v1.serializers.ChildrenMenuOptionSerializer'

SECTION_MENU_OPTION_SERIALIZER = 'wagtailmenus.api.v1.serializers.SectionMenuOptionSerializer'

MAIN_MENU_OPTION_SERIALIZER = 'wagtailmenus.api.v1.serializers.MainMenuOptionSerializer'

FLAT_MENU_OPTION_SERIALIZER = 'wagtailmenus.api.v1.serializers.FlatMenuOptionSerializer'

# -----------------------
# Menu serializer classes
# -----------------------

CHILDREN_MENU_SERIALIZER = 'wagtailmenus.api.v1.serializers.ChildrenMenuSerializer'

SECTION_MENU_SERIALIZER = 'wagtailmenus.api.v1.serializers.SectionMenuSerializer'

MAIN_MENU_BASE_SERIALIZER = 'wagtailmenus.api.v1.serializers.BaseModelMenuSerializer'

FLAT_MENU_BASE_SERIALIZER = 'wagtailmenus.api.v1.serializers.BaseModelMenuSerializer'

# --------------
# View behaviour
# --------------

SINGLE_SITE_MODE = False

CURRENT_SITE_DERIVATION_FUNCTION = 'wagtailmenus.api.utils.derive_current_site'

CURRENT_PAGE_DERIVATION_FUNCTION = 'wagtailmenus.api.utils.derive_current_page'
9 changes: 9 additions & 0 deletions wagtailmenus/api/v1/conf/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys
from cogwheels import BaseAppSettingsHelper


class WagtailmenusAPISettingsHelper(BaseAppSettingsHelper):
deprecations = ()


sys.modules[__name__] = WagtailmenusAPISettingsHelper()
Loading