Skip to content

Commit

Permalink
Fixed #6737 -- Fix 'urls.W001' warning with custom apphook urls (#6738)
Browse files Browse the repository at this point in the history
* Refs #6737 -- Add test for apphooks urls config check

* Fixed #6737 -- Fix 'urls.W001' warning with custom apphook urls

When rewriting the apphooks urls in appresolver.recurse_patterns,
the original RegexPattern.is_endpoint flag is lost, so urls with a callback
view throws an "include with a route ending with a '$'" warning ('urls.W001').

    @apphook_pool.register
    class MyApp(CMSApp):
        name = "MyApp"

        def get_urls(self, page=None, language=None, **kwargs):
            return [
                re_path(r"^$", views.MyAppView.as_view(), name="my-app-index")
                # or this
                # path(r"", views.MyAppView.as_view(), name="my-app-index")
            ]

    $ ./manage.py check
    System check identified some issues:

    WARNINGS:
    ?: (urls.W001) Your URL pattern '^my-app-url/my-view-url/$' [name='my-app-index']
    uses include with a route ending with a '$'. Remove the dollar from the
    route to avoid problems including URLs.

This fix set the RegexPattern flag is_endpoint to True for callback views
in appresolver.recurse_patterns as in
https://github.com/django/django/blob/stable/2.2.x/django/urls/conf.py#L70
  • Loading branch information
rsalmaso authored and FinalAngel committed Nov 11, 2019
1 parent dc3267d commit 9cb5ab6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.txt
Expand Up @@ -10,6 +10,7 @@
* Fixed a bug where the menu would render draft pages even if the page on
the request was a public page. This happens when a user without change
permissions requests edit mode.
* Fixed the 'urls.W001' warning with custom apphook urls
* Prevent non-staff users to login with the django CMS toolbar
* Added missing ``{% trans %}?? to toolbar shortcuts.
* Updated branch policy.
Expand All @@ -18,7 +19,6 @@
* Improved CMSPluginBase documentation.
* Improved documentation related to nested plugins.


=== 3.7.0 (2019-09-25) ===

* Introduced Django 2.2 support.
Expand Down
2 changes: 1 addition & 1 deletion cms/appresolver.py
Expand Up @@ -149,7 +149,7 @@ def recurse_patterns(path, pattern_list, page_id, default_args=None,

regex_pattern = regex
if not DJANGO_1_11:
regex_pattern = RegexPattern(regex, name=pattern.name)
regex_pattern = RegexPattern(regex, name=pattern.name, is_endpoint=True)
resolver = URLPattern(regex_pattern, pattern.callback, args,
pattern.name)
resolver.page_id = page_id
Expand Down
10 changes: 10 additions & 0 deletions cms/tests/test_apphooks.py
Expand Up @@ -9,6 +9,7 @@
from django.contrib.sites.models import Site
from django.core import checks
from django.core.cache import cache
from django.core.checks.urls import check_url_config
from django.test.utils import override_settings
from django.urls import NoReverseMatch, clear_url_caches, resolve, reverse
from django.utils import six
Expand Down Expand Up @@ -124,6 +125,15 @@ def create_base_structure(self, apphook, title_langs, namespace=None):

return titles

@override_settings(ROOT_URLCONF='cms.test_utils.project.fourth_urls_for_apphook_tests')
def test_check_url_config(self):
"""
Test for urls config check.
"""
self.apphook_clear()
result = check_url_config(None)
self.assertEqual(len(result), 0)

@override_settings(CMS_APPHOOKS=['%s.%s' % (APP_MODULE, APP_NAME)])
def test_explicit_apphooks(self):
"""
Expand Down

0 comments on commit 9cb5ab6

Please sign in to comment.