10000 Introduced app registration system by monikasulik · Pull Request #6421 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

Introduced app registration system #6421

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

Merged
merged 28 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4f4139e
App registry: autodiscover
monikasulik Jun 14, 2018
7db2fc9
App registration: Add cms_app attr to django app config
monikasulik Jun 14, 2018
0394871
App registration: run extension methods
monikasulik Jun 15, 2018
0ee728e
App registration: Some clean up
monikasulik Jun 15, 2018
f79f575
App registration: Edge cases
monikasulik Jun 15, 2018
f329f22
App registration: Configure CMS apps
monikasulik Jun 18, 2018
b5f1825
App registration: More clean up
monikasulik Jun 18, 2018
5b88aa1
Merge pull request #3 from monikasulik/app_registration_config
monikasulik Jun 19, 2018
c9f064d
App registration: Test comments
monikasulik Jun 19, 2018
e53eac3
App registration: Integrate into start up (WIP)
monikasulik Jun 21, 2018
f2299db
App registration: Clean up
monikasulik Jun 21, 2018
2416687
Merge pull request #4 from monikasulik/app_registration_start_up
monikasulik Jun 21, 2018
ec35c49
App registration: Remove import test (inconsistent across envs) and u…
monikasulik Jun 21, 2018
5968fc9
App registration: Clean up CMSAppConfig class
monikasulik Jun 21, 2018
c1b606e
Move app registration test apps to test_utils
monikasulik Jun 22, 2018
367e49f
App registration: CHANGELOG and AUTHORS changes
monikasulik Jun 22, 2018
31d767d
Merge pull request #5 from monikasulik/app_registration_improvements
monikasulik Jun 22, 2018
d908a66
App registration: Various minor changes after code review
monikasulik Jun 25, 2018
093408c
App registration: Split app config into 2 classes
monikasulik Jun 25, 2018
263c1c5
App registration: Polish up after separating config base classes
monikasulik Jun 25, 2018
741a803
Merge pull request #6 from monikasulik/app_registration_improvements
monikasulik Jun 25, 2018
bcc02f4
Fix python 2.7 compatibility issue
monikasulik Jun 26, 2018
e64a652
App registration: Improvements after code review
monikasulik Jun 26, 2018
6a55666
Clean up
monikasulik Jun 26, 2018
9f3f6f2
Clean up
monikasulik Jun 26, 2018
6e683d9
Fix abc import for python 2.7
monikasulik Jun 26, 2018
0850fd1
App registration: Clean up
monikasulik Jun 26, 2018
2055642
Minor cleanup
czpython Jun 26, 2018
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
Prev Previous commit
Next Next commit
App registration: Various minor changes after code review
  • Loading branch information
monikasulik committed Jun 25, 2018
commit d908a66a3a28961b33e7e3b8890a312b8921228c
5 changes: 0 additions & 5 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
=== 4.0.0 (unreleased) ===

* Added app registration system.


=== 3.6.0 (unreleased) ===

* Removed the ``cms moderator`` command.
Expand Down
2 changes: 1 addition & 1 deletion cms/app_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ def configure_app(self, app):

:param app: django app that has defined the feature as enabled
Copy link
Contributor

Choose a reason for hiding this comment

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

param is now cms_config

"""
raise NotImplementedError()
raise NotImplementedError
14 changes: 6 additions & 8 deletions cms/app_registration.py
10000
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import inspect
from functools import lru_cache
from importlib import import_module

from django.apps import apps
Expand Down Expand Up @@ -52,18 +53,15 @@ def autodiscover_cms_configs():
"class which inherits from CMSAppConfig")


@lru_cache(maxsize=None)
def get_cms_apps():
Copy link
Contributor

Choose a reason for hiding this comment

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

decorate with lru_cache(max_size=None)

"""
Returns django app configs of apps with a cms config
"""
cms_apps = []

for app_config in apps.get_app_configs():
# The cms_app attr is added by the autodiscover_cms_configs
# function if a cms_config.py file with a suitable class is found.
if hasattr(app_config, 'cms_app'):
cms_apps.append(app_config)

# NOTE: The cms_app attr is added by the autodiscover_cms_configs
# function if a cms_config.py file with a suitable class is found.
cms_apps = [app_config for app_config in apps.get_app_configs()
if hasattr(app_config, 'cms_app')]
return cms_apps


Expand Down
4 changes: 3 additions & 1 deletion cms/test_utils/project/app_with_bad_cms_file/cms_config.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
raise KeyError
# Use this app to test what happens when exceptions are raised in this
# file. RuntimeError is just an example exception
raise RuntimeError
18 changes: 16 additions & 2 deletions cms/tests/test_app_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def test_adds_cms_app_attribute_to_django_app_config(self):
'cms.test_utils.project.app_with_bad_cms_file',
])
def test_raises_exception_raised_in_cms_file(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to test_exception_propagates_from_cms_file

# The cms file intentionally raises a KeyError. We need
# The cms file intentionally raises a RuntimeError. We need
# to make sure the exception definitely bubbles up and doesn't
# get caught.
with self.assertRaises(KeyError):
with self.assertRaises(RuntimeError):
app_registration.autodiscover_cms_configs()

@override_settings(INSTALLED_APPS=[
Expand All @@ -57,6 +57,13 @@ def test_raises_exception_when_more_than_one_cms_app_class_found_in_cms_file(sel

class GetCmsAppsTestCase(CMSTestCase):

def setUp(self):
# The result of get_cms_apps is cached. Clear this cache
# because installed apps change between tests and therefore
# unlike in a live environment, results of this function
# can change between tests
app_registration.get_cms_apps.cache_clear()

@patch.object(apps, 'get_app_configs')
def test_returns_only_cms_apps(self, mocked_apps):
# apps with cms_app attr and a configure method
Expand Down Expand Up @@ -216,6 +223,13 @@ def test_runs_configure_app_method_for_correct_apps_when_multiple_apps(

class SetupCmsAppsTestCase(CMSTestCase):

def setUp(self):
# The result of get_cms_apps is cached. Clear this cache
# because installed apps change between tests and therefore
# unlike in a live environment, results of this function
# can change between tests
app_registration.get_cms_apps.cache_clear()

@patch.object(setup, 'setup_cms_apps')
def test_setup_cms_apps_function_run_on_startup(self, mocked_setup):
cms_module = import_module('cms')
Expand Down
6 changes: 4 additions & 2 deletions cms/utils/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

from cms.utils.compat.dj import is_installed as app_is_installed
from cms.app_registration import (
Copy link
Contributor

Choose a reason for hiding this comment

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

import order.
move this one before utils import

autodiscover_cms_configs, get_cms_apps,
configure_cms_apps)
autodiscover_cms_configs,
configure_cms_apps,
get_cms_apps,
)


def validate_dependencies():
Expand Down
0