8000 fix: Fall back to class name when app name is None (#8059) · django-cms/django-cms@17343b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 17343b0

Browse files
halitcelikfsbraun
andauthored
fix: Fall back to class name when app name is None (#8059)
* Fall back to class name when app name is None * Adds a check for CMSApps without name and test --------- Co-authored-by: Fabian Braun 8000 <fsbraun@gmx.de>
1 parent 69962fe commit 17343b0

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

cms/apphook_pool.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ def get_apphooks(self):
7373

7474
for app_name in self.apps:
7575
app = self.apps[app_name]
76-
7776
if app.get_urls():
78-
hooks.append((app_name, app.name))
77+
hooks.append((app_name, app.name or app_name))
7978

8079
# Unfortunately, we lose the ordering since we now have a list of
8180
# tuples. Let's reorder by app_name:

cms/tests/test_apphooks.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
from cms.api import create_page, create_page_content
1616
from cm 8000 s.app_base import CMSApp
1717
from cms.apphook_pool import apphook_pool
18-
from cms.appresolver import (
19-
applications_page_check,
20-
clear_app_resolvers,
21-
get_app_patterns,
22-
)
18+
from cms.appresolver import applications_page_check, clear_app_resolvers, get_app_patterns
2319
from cms.middleware.page import get_page
2420
from cms.models import PageContent
2521
from cms.test_utils.project.placeholderapp.models import Example1
@@ -332,6 +328,27 @@ def test_apphooks_with_excluded_permissions(self):
332328
self.assertEqual(not_excluded_response.status_code, 302)
333329
self.apphook_clear()
334330

331+
@override_settings(CMS_APPHOOKS=[f'{APP_MODULE}.{APP_NAME}'])
332+
def test_apphook_without_name_defaults_to_class_name(self):
333+
"""
334+
Test that an apphook without a name defaults to the class name.
335+
"""
336+
@apphook_pool.register
337+
class AppWithoutName(CMSApp):
338+
def get_urls(self, page=None, language=None, **kwargs):
339+
return ["sampleapp.urls"]
340+
341+
@apphook_pool.register
342+
class AppWithName(CMSApp):
343+
name = "Custom name"
344+
def get_urls(self, page=None, language=None, **kwargs):
345+
return ["sampleapp.urls"]
346+
347+
hooks = apphook_pool.get_apphooks()
348+
hook_names = dict(hooks)
349+
self.assertEqual(hook_names.get('AppWithoutName'), 'AppWithoutName')
350+
self.assertEqual(hook_names.get('AppWithName'), 'Custom name')
351+
335352
@override_settings(ROOT_URLCONF='cms.test_utils.project.urls_3')
336353
def test_get_page_for_apphook_on_preview_or_edit(self):
337354
if get_user_model().USERNAME_FIELD == 'email':

cms/tests/test_check.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ def test_non_numeric_site_id(self):
135135
with self.settings(SITE_ID='broken'):
136136
self.assertCheck(False, warnings=0, errors=1)
137137

138+
def test_cmsapps_check(self):
139+
from cms.app_base import CMSApp
140+
from cms.apphook_pool import apphook_pool
141+
class AppWithoutName(CMSApp):
142+
def get_urls(self, page=None, language=None, **kwargs):
143+
return ["sampleapp.urls"]
144+
145+
app = apphook_pool.register(AppWithoutName)
146+
147+
self.assertCheck(True, warnings=1, errors=0)
148+
apphook_pool.apps.pop(app.__name__)
138149

139150
class CheckWithDatabaseTests(CheckAssertMixin, TestCase):
140151

cms/utils/check.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,18 @@ def check_template_conf(output):
371371
"Will run in headless mode with one placeholder called \"content\"")
372372

373373

374+
@define_check
375+
def check_cmsapps_names(output):
376+
from cms.apphook_pool import apphook_pool
377+
with output.section("Apphooks") as section:
378+
for hook, name in apphook_pool.get_apphooks():
379+
if apphook_pool.get_apphook(hook).name is None:
380+
section.warn("CMSApps should define a name. %s doesn't have a name" % name)
381+
if section.successful:
382+
section.finish_success("CMSApps configuration is okay")
383+
384+
385+
374386
def check(output):
375387
"""
376388
Checks the configuration/environment of this django CMS installation.

0 commit comments

Comments
 (0)
0